Unverified Commit 7cc8134f authored by Mateu Aguiló Bosch's avatar Mateu Aguiló Bosch Committed by Mateu Aguiló Bosch
Browse files

Issue #3307276 by e0ipso: Invoke form hooks so components can alter their editorial form

parent dec5083d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ function cl_block_cl_component_audit_alter(array &$card_build, Component $compon
      )
    );
  }
  $card_build['table']['#rows'][0][] = in_array($component->getId(), $allowed_components)
  $card_build['table']['#rows'][0][] = in_array($component->getId(), $allowed_components, TRUE)
    ? \t('🌕 Generates a block')
    : \t('🌑 No block');
}
+7 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ namespace Drupal\cl_block\Form;

use Drupal\cl_components\Component\ComponentDiscovery;
use Drupal\cl_components\Exception\ComponentNotFoundException;
use Drupal\cl_components\Exception\InvalidComponentHookException;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Ajax\AjaxResponse;
@@ -181,6 +182,12 @@ class ClBlockDialog extends FormBase {
      '#suffix' => '</div>',
      '#weight' => 5,
    ];
    try {
      $component_form = $component->invokeHook('form_alter', [$component_form, $form_state]);
    }
    catch (InvalidComponentHookException $e) {
      // The component does not support this hook. It is fine, do nothing.
    }
    if (\Drupal::moduleHandler()->moduleExists('token')) {
      $form['tree'] = [
        '#theme' => 'token_tree_link',
+13 −1
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\cl_block\Form;
use Drupal\cl_components\Component\Component;
use Drupal\cl_components\Component\ComponentDiscovery;
use Drupal\cl_components\Exception\ComponentNotFoundException;
use Drupal\cl_components\Exception\InvalidComponentHookException;
use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Form\FormStateInterface;
@@ -34,15 +35,20 @@ class ClComponentForm {
  ) {
  }


  /**
   * Builds the form for a component.
   *
   * @param array $form
   *   The form.
   * @param \Drupal\Core\Form\FormStateInterface $form_state
   *   The form state.
   * @param array $config
   *   The config.
   *
   * @return array
   *   The form.
   *
   * @throws \Drupal\cl_components\Exception\ComponentNotFoundException
   */
  public function buildForm(array $form, FormStateInterface $form_state, array $config): array {
    $this->config = $config;
@@ -114,6 +120,12 @@ class ClComponentForm {
        '#token_types' => ['node', 'user'],
      ];
    }
    try {
      $form['component'] = $component->invokeHook('form_alter', [$form['component'], $form_state]);
    }
    catch (InvalidComponentHookException $e) {
      // The component does not support this hook. It is fine, do nothing.
    }
    return $form;
  }