Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@

# Ignore IDE files
/.idea
.ddev
2 changes: 2 additions & 0 deletions config/sync/core.extension.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module:
contextual: 0
datetime: 0
dblog: 0
drupal_site_core: 0
dynamic_page_cache: 0
editor: 0
entity_browser: 0
Expand Down Expand Up @@ -46,6 +47,7 @@ module:
path_alias: 0
search: 0
shortcut: 0
simple_form: 0
system: 0
taxonomy: 0
text: 0
Expand Down
3 changes: 3 additions & 0 deletions config/sync/user.role.anonymous.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
module:
- comment
- contact
- content_moderation
- filter
- media
- search
Expand All @@ -23,4 +24,6 @@ permissions:
- 'access site-wide contact form'
- 'search content'
- 'use text format restricted_html'
- 'view any unpublished content'
- 'view latest version'
- 'view media'
3 changes: 3 additions & 0 deletions config/sync/user.role.authenticated.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ dependencies:
module:
- comment
- contact
- content_moderation
- file
- filter
- media
Expand All @@ -29,4 +30,6 @@ permissions:
- 'search content'
- 'skip comment approval'
- 'use text format basic_html'
- 'view any unpublished content'
- 'view latest version'
- 'view media'
5 changes: 5 additions & 0 deletions config/sync/workflows.workflow.editorial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ langcode: en
status: true
dependencies:
config:
- media.type.remote_video
- media.type.video
- node.type.landing_page
module:
- content_moderation
Expand Down Expand Up @@ -62,6 +64,9 @@ type_settings:
to: published
weight: 1
entity_types:
media:
- remote_video
- video
node:
- landing_page
default_moderation_state: draft
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ name: 'Custom core'
type: module
description: "Base module (default config, general tasks/updates, etc.)."
core_version_requirement: '^9.4 || ^10'
package: Custom
package: Assessment
59 changes: 55 additions & 4 deletions web/modules/custom/drupal_site_core/drupal_site_core.module
Original file line number Diff line number Diff line change
@@ -1,6 +1,57 @@
<?php

/**
* @file
* Contains drupal_site_core.module.
*/
// /**
// * @file
// * Contains drupal_site_core.module.
// */

function drupal_site_core_entity_update(Drupal\Core\Entity\EntityInterface $entity) {
static $is_updating = FALSE;

if ($is_updating) {
return;
}

if ($entity->getEntityTypeId() == 'media' && $entity->bundle() == 'remote_video') {
$node = \Drupal::routeMatch()->getParameter('node');

if ($node && !$node->isDefaultRevision()) {
if ($entity->hasField('moderation_state') && $entity->get('moderation_state')->value !== 'draft') {
$violations = $entity->validate();
if (count($violations) > 0) {
foreach ($violations as $violation) {
\Drupal::messenger()->addError($violation->getMessage());
}
return;
}

if (!\Drupal::currentUser()->hasPermission('edit media')) {
\Drupal::messenger()->addError('You do not have permission to edit this media entity.');
return;
}

$is_updating = TRUE;

$entity->set('moderation_state', 'draft');

$entity->setNewRevision(TRUE);

$entity->setRevisionUserId(\Drupal::currentUser()->id());

$entity->setRevisionLogMessage('Set moderation state to draft programmatically.');

try {
if ($entity->save()) {
\Drupal::messenger()->addMessage('Set moderation state to draft programmatically.');
} else {
\Drupal::messenger()->addError('Entity save returned false.');
}
} catch (\Exception $e) {
\Drupal::messenger()->addError('An error occurred during entity save: ' . $e->getMessage());
}

$is_updating = FALSE;
}
}
}
}
12 changes: 12 additions & 0 deletions web/modules/custom/simple_form/simple_form.info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: 'Practical Coding Challenges'
description: 'Provides a simple form with two fields: a text
field and a select list. Upon submission, the form should save the data to a
custom table in the database and display a confirmation message.'
package: Assessment
core_version_requirement: ^10
type: module

version: '1.0'
datestamp: 1630242476
dependencies:
- drupal:field
6 changes: 6 additions & 0 deletions web/modules/custom/simple_form/simple_form.links.menu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
simple_form.admin_config_form:
title: 'Simple Form'
description: 'Configure the Simple Form.'
parent: system.admin_config_system
route_name: simple_form.form
weight: 100
38 changes: 38 additions & 0 deletions web/modules/custom/simple_form/simple_form.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* @file
* Contains the implementation of the Simple Form module.
*/

/**
* Implements hook_install().
*/
function simple_form_install() {
\Drupal::database()->schema()->createTable('simple_form_data', [
'fields' => [
'id' => [
'type' => 'serial',
'not null' => TRUE,
],
'text_field' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
],
'select_field' => [
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
],
],
'primary key' => ['id'],
]);
}

/**
* Implements hook_uninstall().
*/
function simple_form_uninstall() {
\Drupal::database()->schema()->dropTable('simple_form_data');
}
7 changes: 7 additions & 0 deletions web/modules/custom/simple_form/simple_form.routing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
simple_form.form:
path: '/admin/simple-form'
defaults:
_form: '\Drupal\simple_form\Form\SimpleForm'
_title: 'Simple Form'
requirements:
_permission: 'access content'
85 changes: 85 additions & 0 deletions web/modules/custom/simple_form/src/Form/SimpleForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

namespace Drupal\simple_form\Form;

use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Database\Database;

/**
* Provides a Simple Form.
*/
class SimpleForm extends FormBase {

/**
* {@inheritdoc}
*/
public function getFormId() {
return 'simple_form';
}

/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$connection = Database::getConnection();
$query = $connection->select('simple_form_data', 'sfd')
->fields('sfd', ['text_field', 'select_field'])
->orderBy('id', 'DESC')
->range(0, 1);
$result = $query->execute()->fetchAssoc();

$default_text = isset($result['text_field']) ? $result['text_field'] : '';
$default_select = isset($result['select_field']) ? $result['select_field'] : '';

$form['text_field'] = [
'#type' => 'textfield',
'#title' => $this->t('Text Field'),
'#default_value' => $default_text,
'#required' => TRUE,
];

$form['select_field'] = [
'#type' => 'select',
'#title' => $this->t('Select Field'),
'#options' => [
'option_1' => $this->t('Option 1'),
'option_2' => $this->t('Option 2'),
'option_3' => $this->t('Option 3'),
],
'#default_value' => $default_select,
'#required' => TRUE,
];

$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];

return $form;
}

/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
}

/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$text = $form_state->getValue('text_field');
$select = $form_state->getValue('select_field');

$connection = Database::getConnection();
$connection->insert('simple_form_data')
->fields([
'text_field' => $text,
'select_field' => $select,
])
->execute();

$this->messenger()->addMessage($this->t('The form has been submitted successfully.'));
}
}