Loading modules/custom_elements_ui/custom_elements_ui.module 0 → 100644 +68 −0 Original line number Diff line number Diff line <?php /** * @file * Provides hook implementations for Custom Elements UI. */ use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\field_ui\Form\EntityViewDisplayEditForm; /** * Implements hook_entity_type_alter(). */ function custom_elements_ui_entity_type_alter(array &$entity_types) { /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ $entity_types['entity_view_display'] ->setFormClass('custom_elements_builder', EntityViewDisplayEditForm::class); // Ensure every fieldable entity type has a layout form. foreach ($entity_types as $entity_type) { if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) { $entity_type->setFormClass('custom_elements_builder', EntityViewDisplayEditForm::class); } } } /** * Implements hook_form_FORM_ID_alter() for \Drupal\field_ui\Form\EntityFormDisplayEditForm. */ function custom_elements_ui_form_entity_form_display_edit_form_alter(&$form, FormStateInterface $form_state) { // @todo Get value from config. // $is_enabled = $this->third_party_settings[$module][$key]; $is_enabled = FALSE; if ($is_enabled) { // Hide the table of fields. $form['fields']['#access'] = FALSE; $form['#fields'] = []; $form['#extra'] = []; } $form['manage_custom_elements'] = [ '#type' => 'link', '#title' => t('Manage custom elements'), '#weight' => -10, '#attributes' => ['class' => ['button']], // @todo Add correct url. '#url' => Url::fromRoute('<front>'), '#access' => $is_enabled, ]; $form['layout'] = [ '#type' => 'details', '#open' => TRUE, '#title' => t('Custom Elements'), '#tree' => TRUE, ]; $form['layout']['enabled'] = [ '#type' => 'checkbox', '#title' => t('Use Custom Elements Builder'), // @todo What about "Custom Elements Builder" naming? '#default_value' => $is_enabled, ]; } modules/custom_elements_ui/src/Routing/RouteSubscriber.php +2 −2 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ class RouteSubscriber extends RouteSubscriberBase { $route = new Route( "$path/ce", [ '_entity_form' => 'entity_view_display.edit', '_entity_form' => 'entity_view_display.custom_elements_builder', '_title' => 'Manage CE', 'view_mode_name' => 'default', ] + $defaults, Loading @@ -81,7 +81,7 @@ class RouteSubscriber extends RouteSubscriberBase { $route = new Route( "$path/ce/{view_mode_name}", [ '_entity_form' => 'entity_view_display.edit', '_entity_form' => 'entity_view_display.custom_elements_builder', '_title' => 'Manage CE', ] + $defaults, // @todo Own access checking. Loading Loading
modules/custom_elements_ui/custom_elements_ui.module 0 → 100644 +68 −0 Original line number Diff line number Diff line <?php /** * @file * Provides hook implementations for Custom Elements UI. */ use Drupal\Core\Entity\FieldableEntityInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Url; use Drupal\field_ui\Form\EntityViewDisplayEditForm; /** * Implements hook_entity_type_alter(). */ function custom_elements_ui_entity_type_alter(array &$entity_types) { /** @var \Drupal\Core\Entity\EntityTypeInterface[] $entity_types */ $entity_types['entity_view_display'] ->setFormClass('custom_elements_builder', EntityViewDisplayEditForm::class); // Ensure every fieldable entity type has a layout form. foreach ($entity_types as $entity_type) { if ($entity_type->entityClassImplements(FieldableEntityInterface::class)) { $entity_type->setFormClass('custom_elements_builder', EntityViewDisplayEditForm::class); } } } /** * Implements hook_form_FORM_ID_alter() for \Drupal\field_ui\Form\EntityFormDisplayEditForm. */ function custom_elements_ui_form_entity_form_display_edit_form_alter(&$form, FormStateInterface $form_state) { // @todo Get value from config. // $is_enabled = $this->third_party_settings[$module][$key]; $is_enabled = FALSE; if ($is_enabled) { // Hide the table of fields. $form['fields']['#access'] = FALSE; $form['#fields'] = []; $form['#extra'] = []; } $form['manage_custom_elements'] = [ '#type' => 'link', '#title' => t('Manage custom elements'), '#weight' => -10, '#attributes' => ['class' => ['button']], // @todo Add correct url. '#url' => Url::fromRoute('<front>'), '#access' => $is_enabled, ]; $form['layout'] = [ '#type' => 'details', '#open' => TRUE, '#title' => t('Custom Elements'), '#tree' => TRUE, ]; $form['layout']['enabled'] = [ '#type' => 'checkbox', '#title' => t('Use Custom Elements Builder'), // @todo What about "Custom Elements Builder" naming? '#default_value' => $is_enabled, ]; }
modules/custom_elements_ui/src/Routing/RouteSubscriber.php +2 −2 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ class RouteSubscriber extends RouteSubscriberBase { $route = new Route( "$path/ce", [ '_entity_form' => 'entity_view_display.edit', '_entity_form' => 'entity_view_display.custom_elements_builder', '_title' => 'Manage CE', 'view_mode_name' => 'default', ] + $defaults, Loading @@ -81,7 +81,7 @@ class RouteSubscriber extends RouteSubscriberBase { $route = new Route( "$path/ce/{view_mode_name}", [ '_entity_form' => 'entity_view_display.edit', '_entity_form' => 'entity_view_display.custom_elements_builder', '_title' => 'Manage CE', ] + $defaults, // @todo Own access checking. Loading