Skip to content
Snippets Groups Projects
Commit 724e0df1 authored by Igor Biki's avatar Igor Biki
Browse files

Merge branch 'feature/ISTWCMS-7182-l26yan-quote_text_field_required_indicator' into '1.1.x'

ISTWCMS-7182 Blockquote block quote text field should show it is required

See merge request !255
parents 89005dfb 18efe8ef
No related branches found
No related tags found
1 merge request!255ISTWCMS-7182 Blockquote block quote text field should show it is required
......@@ -23,7 +23,7 @@ entity_type: block_content
bundle: uw_cbl_blockquote
label: 'Quote text'
description: ''
required: false
required: true
translatable: false
default_value: { }
default_value_callback: ''
......
......@@ -2,9 +2,6 @@
namespace Drupal\uw_custom_blocks\EventSubscriber;
use Drupal\Core\Form\FormStateInterface;
use Drupal\core_event_dispatcher\Event\Form\FormAlterEvent;
use Drupal\core_event_dispatcher\FormHookEvents;
use Drupal\preprocess_event_dispatcher\Event\BlockPreprocessEvent;
use Drupal\uw_custom_blocks\CustomBlocks\UwCblBase;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......@@ -14,53 +11,6 @@ use Symfony\Component\EventDispatcher\EventSubscriberInterface;
*/
class UwCblBlockquoteEventSubscriber extends UwCblBase implements EventSubscriberInterface {
/**
* Alter form.
*
* @param \Drupal\core_event_dispatcher\Event\Form\FormAlterEvent $event
* The event.
*/
public function alterForm(FormAlterEvent $event): void {
if ($this->checkLayoutBuilder($event, 'Blockquote')) {
// Get the form from the event.
$form = &$event->getForm();
// Add the validation for blockquote.
$form['#validate'][] = [$this, 'validateBlockquote'];
}
}
/**
* Form validation for blockquote.
*
* @param array $form
* The complete form structure.
* @param \Drupal\Core\Form\FormStateInterface $form_state
* The form state.
*/
public function validateBlockquote(array &$form, FormStateInterface $form_state) {
// Get the settings from the form.
$settings = $form_state->getValue('settings', NULL);
// If there are settings, continue to process.
if ($settings) {
// If there is a block, continue to process.
if ($block = $settings['block_form']) {
// If there is no text in the quote text, set error.
if ($block['field_uw_bq_quote_text'][0]['value'] == '') {
// Set the form error for not having any quote text.
$form_state->setErrorByName('settings][block_form][field_uw_bq_quote_text', 'You must enter quote text.');
}
}
}
}
/**
* Preprocess blocks with blockquote and set variables.
*
......@@ -104,7 +54,6 @@ class UwCblBlockquoteEventSubscriber extends UwCblBase implements EventSubscribe
*/
public static function getSubscribedEvents() {
return [
FormHookEvents::FORM_ALTER => 'alterForm',
BlockPreprocessEvent::name() => 'preprocessBlock',
];
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment