association-1.0.0-alpha2/modules/association_page/association_page.module
modules/association_page/association_page.module
<?php /** * @file * Drupal hooks and global functionality for the association_page module. */ use Drupal\association\Entity\AssociationTypeInterface; use Drupal\association_page\Plugin\Association\LandingPage\AssociationPage; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\StringTranslation\TranslatableMarkup; use Drupal\Core\Url; /** * Implements hook_menu_links_discovered_alter(). */ function association_page_menu_links_discovered_alter(array &$links) { $module_handler = \Drupal::moduleHandler(); // If the admin_toolbar_tools module is enabled, correct the menu links for // the association page entity management settings. if (!$module_handler->moduleExists('admin_toolbar_tools')) { return; } /** @var \Drupal\association\Entity\AssociationTypeInterface[] */ $assoc_types = \Drupal::entityTypeManager() ->getStorage('association_type') ->loadMultiple(); $prefix = 'admin_toolbar_tools.extra_links:'; $entity_links = [ 'entity.association_page.field_ui_fields' => t('Page fields'), 'entity.entity_form_display.association_page.default' => t('Page form display'), 'entity.entity_view_display.association_page.default.' => t('Page display'), ]; foreach ($assoc_types as $type_id => $assoc_type) { foreach ($entity_links as $link => $title) { $key = $prefix . $link . $type_id; if (!isset($links[$key])) { continue; } if ($assoc_type->getPlugin('landing_page') instanceof AssociationPage) { // Set menu titles for the association page entity manage links. $links[$key]['title'] = $title; } else { // If page is not enabled for this type, remove the association page // entity manage admin forms. unset($links[$key]); } } } } /** * Implements hook_local_tasks_alter(). */ function association_page_local_tasks_alter(&$local_tasks) { $field_overview = 'field_ui.fields:overview_association'; $field_form_display = 'field_ui.fields:form_display_overview_association'; $field_view_display = 'field_ui.fields:display_overview_association'; // Adjust the association fields management page local tasks. if (isset($local_tasks[$field_overview]) && isset($local_tasks[$field_overview . '_page'])) { $local_tasks[$field_overview . '_page']['title'] = t('Page fields'); $local_tasks[$field_overview . '_page']['parent_id'] = $field_overview; $local_tasks[$field_overview . '_page']['base_route'] = NULL; $local_tasks[$field_overview . '_page']['weight'] = 10; } // Move the field form display local task to the association type edit page. if (isset($local_tasks[$field_form_display]) && isset($local_tasks[$field_form_display . '_page'])) { $local_tasks[$field_form_display . '_page']['title'] = t('Page form'); $local_tasks[$field_form_display . '_page']['parent_id'] = $local_tasks[$field_form_display]['parent_id']; $local_tasks[$field_form_display . '_page']['base_route'] = $local_tasks[$field_form_display]['base_route']; } // Move the field view display local task to the association type edit page. if (isset($local_tasks[$field_view_display]) && isset($local_tasks[$field_view_display . '_page'])) { $local_tasks[$field_view_display . '_page']['title'] = t('Page display'); $local_tasks[$field_view_display . '_page']['parent_id'] = $local_tasks[$field_view_display]['parent_id']; $local_tasks[$field_view_display . '_page']['base_route'] = $local_tasks[$field_view_display]['base_route']; } // Because of the way we build the association page local tasks, the // automatically generated layout builder task needs an adjustment. $lb_task_key = 'layout_builder_ui:layout_builder.overrides.association_page.view'; if (isset($local_tasks[$lb_task_key])) { $local_tasks[$lb_task_key]['base_route'] = 'entity.association.manage'; $local_tasks[$lb_task_key]['class'] = '\Drupal\association\Menu\AssociationLocalTask'; $local_tasks[$lb_task_key]['weight'] = 15; } } /** * Implements hook_condition_info_alter(). */ function association_page_condition_info_alter(&$conditions) { // Remove CTools derived entity condition plugin for entity associations as // these cause confusion and do not handle the condition plugins correctly. if (isset($conditions['entity_bundle:association_page'])) { unset($conditions['entity_bundle:association_page']); } } /** * Implements hook_entity_operation_alter(). */ function association_page_entity_operation_alter(array &$operations, EntityInterface $entity) { if ($entity instanceof AssociationTypeInterface && 'association_type' === $entity->getEntityTypeId()) { $module_handler = \Drupal::moduleHandler(); $page_plugin = $entity->getLandingPageHandler(); // If association type is using the "association_page" entity add the // manage field operations to the type operations. if ('association_page' !== $page_plugin->getPluginId() || !$module_handler->moduleExists('field_ui')) { return; } $account = \Drupal::currentUser(); $urlParams = ['association_type' => $entity->id()]; if ($account->hasPermission('administer assocation_page fields')) { $operations['manage-page-fields'] = [ 'title' => new TranslatableMarkup('Page fields'), 'weight' => 50, 'url' => Url::fromRoute('entity.association_page.field_ui_fields', $urlParams), ]; } if ($account->hasPermission('administer assocation_page form display')) { $operations['manage-page-form-display'] = [ 'title' => new TranslatableMarkup('Page form display'), 'weight' => 55, 'url' => Url::fromRoute('entity.entity_form_display.association_page.default', $urlParams), ]; } if ($account->hasPermission('administer assocation_page display')) { $operations['manage-page-display'] = [ 'title' => new TranslatableMarkup('Page display'), 'weight' => 55, 'url' => Url::fromRoute('entity.entity_view_display.association_page.default', $urlParams), ]; } } } /** * Implements hook_theme(). */ function association_page_theme($existing, $type, $theme, $path) { return [ 'association_page' => [ 'render element' => 'element', 'pattern' => 'association_page__', 'file' => 'association_page.theme', ], ]; }