Loading src/Form/ClBlockDialog.php +0 −18 Original line number Diff line number Diff line Loading @@ -274,24 +274,6 @@ class ClBlockDialog extends FormBase { return $response; } /** * @return mixed */ private function getComponentSelectOptions(): array { $settings = \Drupal::config('cl_block.settings'); $components = $this->componentDiscovery->findAllWithFilters( $settings->get('allowed'), $settings->get('forbidden'), $settings->get('types'), $settings->get('statuses'), ); ksort($components); return array_map( static fn(Component $component) => $component->getMetadata()->getName(), $components ); } /** * Render API callback: builds the component data elements. */ Loading src/Plugin/EmbedType/ClComponentEmbed.php +1 −43 Original line number Diff line number Diff line Loading @@ -2,8 +2,6 @@ namespace Drupal\cl_block\Plugin\EmbedType; use Drupal\cl_components\Component\Component; use Drupal\cl_components\Component\ComponentDiscovery; use Drupal\Core\Form\FormStateInterface; use Drupal\embed\EmbedType\EmbedTypeBase; Loading Loading @@ -40,53 +38,13 @@ class ClComponentEmbed extends EmbedTypeBase { public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); $form['component_id'] = [ '#type' => 'select', '#type' => 'cl_component_selector', '#title' => $this->t('CL Component'), '#options' => $this->getComponentOptions(), '#default_value' => $this->configuration['component_id'], '#empty_option' => $this->t('- Select one -'), '#required' => TRUE, ]; return $form; } /** * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { parent::submitConfigurationForm($form, $form_state); $this->configuration['component_id'] = $form_state->getValue('component_id'); } /** * Gets the available component options. * * @return array * The options array ready for a select. */ private function getComponentOptions(): array { $components = \Drupal::service(ComponentDiscovery::class)->findAll(); $options = array_reduce( $components, static function (array $carry, Component $component) { $group = $component->getMetadata()->getGroup(); $name = $component->getMetadata()->getName(); $id = $component->getId(); if (empty($carry[$group])) { $carry[$group] = []; } $carry[$group][$id] = $name; return $carry; }, [] ); ksort($options); foreach ($options as $group => $opts) { natsort($options[$group]); } return $options; } } Loading
src/Form/ClBlockDialog.php +0 −18 Original line number Diff line number Diff line Loading @@ -274,24 +274,6 @@ class ClBlockDialog extends FormBase { return $response; } /** * @return mixed */ private function getComponentSelectOptions(): array { $settings = \Drupal::config('cl_block.settings'); $components = $this->componentDiscovery->findAllWithFilters( $settings->get('allowed'), $settings->get('forbidden'), $settings->get('types'), $settings->get('statuses'), ); ksort($components); return array_map( static fn(Component $component) => $component->getMetadata()->getName(), $components ); } /** * Render API callback: builds the component data elements. */ Loading
src/Plugin/EmbedType/ClComponentEmbed.php +1 −43 Original line number Diff line number Diff line Loading @@ -2,8 +2,6 @@ namespace Drupal\cl_block\Plugin\EmbedType; use Drupal\cl_components\Component\Component; use Drupal\cl_components\Component\ComponentDiscovery; use Drupal\Core\Form\FormStateInterface; use Drupal\embed\EmbedType\EmbedTypeBase; Loading Loading @@ -40,53 +38,13 @@ class ClComponentEmbed extends EmbedTypeBase { public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = parent::buildConfigurationForm($form, $form_state); $form['component_id'] = [ '#type' => 'select', '#type' => 'cl_component_selector', '#title' => $this->t('CL Component'), '#options' => $this->getComponentOptions(), '#default_value' => $this->configuration['component_id'], '#empty_option' => $this->t('- Select one -'), '#required' => TRUE, ]; return $form; } /** * {@inheritdoc} */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { parent::submitConfigurationForm($form, $form_state); $this->configuration['component_id'] = $form_state->getValue('component_id'); } /** * Gets the available component options. * * @return array * The options array ready for a select. */ private function getComponentOptions(): array { $components = \Drupal::service(ComponentDiscovery::class)->findAll(); $options = array_reduce( $components, static function (array $carry, Component $component) { $group = $component->getMetadata()->getGroup(); $name = $component->getMetadata()->getName(); $id = $component->getId(); if (empty($carry[$group])) { $carry[$group] = []; } $carry[$group][$id] = $name; return $carry; }, [] ); ksort($options); foreach ($options as $group => $opts) { natsort($options[$group]); } return $options; } }