Example #1
0
 /**
  * Test views internal menu link options.
  */
 public function testMenuLinkOverrides()
 {
     // Link from views module.
     $views_link = $this->menuLinkManager->getDefinition('views_view:views.test_page_display_menu.page_3');
     $this->assertTrue($views_link['enabled'], 'Menu link is enabled.');
     $this->assertFalse($views_link['expanded'], 'Menu link is not expanded.');
     $views_link['enabled'] = 0;
     $views_link['expanded'] = 1;
     $this->menuLinkManager->updateDefinition($views_link['id'], $views_link);
     $views_link = $this->menuLinkManager->getDefinition($views_link['id']);
     $this->assertFalse($views_link['enabled'], 'Menu link is disabled.');
     $this->assertTrue($views_link['expanded'], 'Menu link is expanded.');
     $this->menuLinkManager->rebuild();
     $this->assertFalse($views_link['enabled'], 'Menu link is disabled.');
     $this->assertTrue($views_link['expanded'], 'Menu link is expanded.');
     // Link from user module.
     $user_link = $this->menuLinkManager->getDefinition('user.page');
     $this->assertTrue($user_link['enabled'], 'Menu link is enabled.');
     $user_link['enabled'] = 0;
     $views_link['expanded'] = 1;
     $this->menuLinkManager->updateDefinition($user_link['id'], $user_link);
     $this->assertFalse($user_link['enabled'], 'Menu link is disabled.');
     $this->menuLinkManager->rebuild();
     $this->assertFalse($user_link['enabled'], 'Menu link is disabled.');
     $this->menuLinkOverrides->reload();
     $views_link = $this->menuLinkManager->getDefinition('views_view:views.test_page_display_menu.page_3');
     $this->assertFalse($views_link['enabled'], 'Menu link is disabled.');
     $this->assertTrue($views_link['expanded'], 'Menu link is expanded.');
     $user_link = $this->menuLinkManager->getDefinition('user.page');
     $this->assertFalse($user_link['enabled'], 'Menu link is disabled.');
 }
 /**
  * {@inheritdoc}
  *
  * Find the parent link GUID.
  */
 public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property)
 {
     $parent_id = array_shift($value);
     if (!$parent_id) {
         // Top level item.
         return '';
     }
     try {
         $already_migrated_id = $this->migrationPlugin->transform($parent_id, $migrate_executable, $row, $destination_property);
         if ($already_migrated_id && ($link = $this->menuLinkStorage->load($already_migrated_id))) {
             return $link->getPluginId();
         }
     } catch (MigrateSkipRowException $e) {
     }
     if (isset($value[1])) {
         list($menu_name, $parent_link_path) = $value;
         $url = Url::fromUserInput("/{$parent_link_path}");
         if ($url->isRouted()) {
             $links = $this->menuLinkManager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters(), $menu_name);
             if (count($links) == 1) {
                 /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
                 $link = reset($links);
                 return $link->getPluginId();
             }
         }
     }
     throw new MigrateSkipRowException();
 }
Example #3
0
 /**
  * Tests creating links with an expected tree structure.
  */
 public function testCreateLinksInMenu()
 {
     // This creates a tree with the following structure:
     // - 1
     // - 2
     //   - 3
     //     - 4
     // - 5
     //   - 7
     // - 6
     // - 8
     // With link 6 being the only external link.
     $links = array(1 => MenuLinkMock::create(array('id' => 'test.example1', 'route_name' => 'example1', 'title' => 'foo', 'parent' => '')), 2 => MenuLinkMock::create(array('id' => 'test.example2', 'route_name' => 'example2', 'title' => 'bar', 'parent' => 'test.example1', 'route_parameters' => array('foo' => 'bar'))), 3 => MenuLinkMock::create(array('id' => 'test.example3', 'route_name' => 'example3', 'title' => 'baz', 'parent' => 'test.example2', 'route_parameters' => array('baz' => 'qux'))), 4 => MenuLinkMock::create(array('id' => 'test.example4', 'route_name' => 'example4', 'title' => 'qux', 'parent' => 'test.example3')), 5 => MenuLinkMock::create(array('id' => 'test.example5', 'route_name' => 'example5', 'title' => 'foofoo', 'parent' => '')), 6 => MenuLinkMock::create(array('id' => 'test.example6', 'route_name' => '', 'url' => 'https://www.drupal.org/', 'title' => 'barbar', 'parent' => '')), 7 => MenuLinkMock::create(array('id' => 'test.example7', 'route_name' => 'example7', 'title' => 'bazbaz', 'parent' => '')), 8 => MenuLinkMock::create(array('id' => 'test.example8', 'route_name' => 'example8', 'title' => 'quxqux', 'parent' => '')));
     foreach ($links as $instance) {
         $this->menuLinkManager->addDefinition($instance->getPluginId(), $instance->getPluginDefinition());
     }
     $parameters = new MenuTreeParameters();
     $tree = $this->linkTree->load('mock', $parameters);
     $count = function (array $tree) {
         $sum = function ($carry, MenuLinkTreeElement $item) {
             return $carry + $item->count();
         };
         return array_reduce($tree, $sum);
     };
     $this->assertEqual($count($tree), 8);
     $parameters = new MenuTreeParameters();
     $parameters->setRoot('test.example2');
     $tree = $this->linkTree->load($instance->getMenuName(), $parameters);
     $top_link = reset($tree);
     $this->assertEqual(count($top_link->subtree), 1);
     $child = reset($top_link->subtree);
     $this->assertEqual($child->link->getPluginId(), $links[3]->getPluginId());
     $height = $this->linkTree->getSubtreeHeight('test.example2');
     $this->assertEqual($height, 3);
 }
 /**
  * {@inheritdoc}
  */
 public function convert($value, $definition, $name, array $defaults, Request $request)
 {
     if ($value) {
         try {
             return $this->menuLinkManager->createInstance($value);
         } catch (PluginException $e) {
             // Suppress the error.
         }
     }
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function build()
 {
     $items = [];
     $current_id = $this->active->getActiveLink('main')->getPluginId();
     while (!empty($current_id)) {
         $current_link = $this->linkManager->createInstance($current_id);
         /** @var MenuLinkContent $current_link */
         $link = new Link($current_link->getTitle(), $current_link->getUrlObject());
         $items[] = $link;
         $current_id = $current_link->getParent();
     }
     $breadcrumbs = new Breadcrumb();
     $breadcrumbs->setLinks(array_reverse($items));
     return $breadcrumbs->toRenderable();
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     // Locked menus may not be deleted.
     if ($this->entity->isLocked()) {
         return;
     }
     // Delete all links to the overview page for this menu.
     // @todo Add a more generic helper function to the menu link plugin
     //   manager to remove links to a entity or other ID used as a route
     //   parameter that is being removed. Also, consider moving this to
     //   menu_ui.module as part of a generic response to entity deletion.
     //   https://www.drupal.org/node/2310329
     $menu_links = $this->menuLinkManager->loadLinksByRoute('entity.menu.edit_form', array('menu' => $this->entity->id()), TRUE);
     foreach ($menu_links as $id => $link) {
         $this->menuLinkManager->removeDefinition($id);
     }
     parent::submitForm($form, $form_state);
 }
 /**
  * Perform menu-specific rebuilding.
  */
 protected function menuLinksRebuild()
 {
     if ($this->lock->acquire(__FUNCTION__)) {
         $transaction = db_transaction();
         try {
             // Ensure the menu links are up to date.
             $this->menuLinkManager->rebuild();
             // Ignore any database replicas temporarily.
             db_ignore_replica();
         } catch (\Exception $e) {
             $transaction->rollback();
             watchdog_exception('menu', $e);
         }
         $this->lock->release(__FUNCTION__);
     } else {
         // Wait for another request that is already doing this work.
         // We choose to block here since otherwise the router item may not
         // be available during routing resulting in a 404.
         $this->lock->wait(__FUNCTION__);
     }
 }
 /**
  * Tests getActiveTrailIds().
  *
  * @covers ::getActiveTrailIds
  * @dataProvider provider
  */
 public function testGetActiveTrailIds(Request $request, $links, $menu_name, $expected_link, $expected_trail)
 {
     $expected_trail_ids = array_combine($expected_trail, $expected_trail);
     $this->requestStack->push($request);
     if ($links !== FALSE) {
         $this->menuLinkManager->expects($this->once())->method('loadLinksbyRoute')->with('baby_llama')->will($this->returnValue($links));
         if ($expected_link !== NULL) {
             $this->menuLinkManager->expects($this->once())->method('getParentIds')->will($this->returnValueMap(array(array($expected_link->getPluginId(), $expected_trail_ids))));
         }
     }
     $this->assertSame($expected_trail_ids, $this->menuActiveTrail->getActiveTrailIds($menu_name));
 }
 /**
  * {@inheritdoc}
  */
 public function getActiveLink($menu_name = NULL)
 {
     // Note: this is a very simple implementation. If you need more control
     // over the return value, such as matching a prioritized list of menu names,
     // you should substitute your own implementation for the 'menu.active_trail'
     // service in the container.
     // The menu links coming from the storage are already sorted by depth,
     // weight and ID.
     $found = NULL;
     $route_name = $this->routeMatch->getRouteName();
     // On a default (not custom) 403 page the route name is NULL. On a custom
     // 403 page we will get the route name for that page, so we can consider
     // it a feature that a relevant menu tree may be displayed.
     if ($route_name) {
         $route_parameters = $this->routeMatch->getRawParameters()->all();
         // Load links matching this route.
         $links = $this->menuLinkManager->loadLinksByRoute($route_name, $route_parameters, $menu_name);
         // Select the first matching link.
         if ($links) {
             $found = reset($links);
         }
     }
     return $found;
 }
Example #10
0
 /**
  * Tests uninstalling a module providing default links.
  */
 public function testModuleUninstalledMenuLinks()
 {
     \Drupal::moduleHandler()->install(array('menu_test'));
     \Drupal::service('router.builder')->rebuild();
     \Drupal::service('plugin.manager.menu.link')->rebuild();
     $menu_links = $this->menuLinkManager->loadLinksByRoute('menu_test.menu_test');
     $this->assertEqual(count($menu_links), 1);
     $menu_link = reset($menu_links);
     $this->assertEqual($menu_link->getPluginId(), 'menu_test');
     // Uninstall the module and ensure the menu link got removed.
     \Drupal::moduleHandler()->uninstall(array('menu_test'));
     \Drupal::service('plugin.manager.menu.link')->rebuild();
     $menu_links = $this->menuLinkManager->loadLinksByRoute('menu_test.menu_test');
     $this->assertEqual(count($menu_links), 0);
 }
 /**
  * Remove menu entries associate with the vocabulary of this term.
  *
  * @param \Drupal\taxonomy\TermInterface $term
  */
 public function removeTaxonomyMenuEntries(TermInterface $term, $rebuild_all = TRUE)
 {
     // Load relevant taxonomy menus.
     $tax_menus = $this->getTermMenusByVocabulary($term->getVocabularyId());
     foreach ($tax_menus as $menu) {
         foreach (array_keys($menu->getLinks([], TRUE)) as $plugin_id) {
             if (!$rebuild_all) {
                 $plugin_id_parts = explode('.', $plugin_id);
                 $term_id = array_pop($plugin_id_parts);
                 if ($term->id() != $term_id) {
                     continue;
                 }
             }
             $this->manager->removeDefinition($plugin_id, FALSE);
         }
     }
 }
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     parent::setUp();
     $this->installSchema('system', 'sequences');
     $this->installEntitySchema('user');
     $this->installSchema('system', array('router'));
     $this->installEntitySchema('menu_link_content');
     $account = User::create(['name' => $this->randomMachineName(), 'status' => 1]);
     $account->save();
     $this->container->get('current_user')->setAccount($account);
     $this->menuLinkManager = $this->container->get('plugin.manager.menu.link');
     $this->linkTree = $this->container->get('menu.link_tree');
     $this->blockManager = $this->container->get('plugin.manager.block');
     $routes = new RouteCollection();
     $requirements = array('_access' => 'TRUE');
     $options = array('_access_checks' => array('access_check.default'));
     $routes->add('example1', new Route('/example1', array(), $requirements, $options));
     $routes->add('example2', new Route('/example2', array(), $requirements, $options));
     $routes->add('example3', new Route('/example3', array(), $requirements, $options));
     $routes->add('example4', new Route('/example4', array(), $requirements, $options));
     $routes->add('example5', new Route('/example5', array(), $requirements, $options));
     $routes->add('example6', new Route('/example6', array(), $requirements, $options));
     $routes->add('example7', new Route('/example7', array(), $requirements, $options));
     $routes->add('example8', new Route('/example8', array(), $requirements, $options));
     $mock_route_provider = new MockRouteProvider($routes);
     $this->container->set('router.route_provider', $mock_route_provider);
     // Add a new custom menu.
     $menu_name = 'mock';
     $label = $this->randomMachineName(16);
     $this->menu = entity_create('menu', array('id' => $menu_name, 'label' => $label, 'description' => 'Description text'));
     $this->menu->save();
     // This creates a tree with the following structure:
     // - 1
     // - 2
     //   - 3
     //     - 4
     // - 5
     //   - 7
     // - 6
     // - 8
     // With link 6 being the only external link.
     $links = array(1 => MenuLinkMock::create(array('id' => 'test.example1', 'route_name' => 'example1', 'title' => 'foo', 'parent' => '', 'weight' => 0)), 2 => MenuLinkMock::create(array('id' => 'test.example2', 'route_name' => 'example2', 'title' => 'bar', 'parent' => '', 'route_parameters' => array('foo' => 'bar'), 'weight' => 1)), 3 => MenuLinkMock::create(array('id' => 'test.example3', 'route_name' => 'example3', 'title' => 'baz', 'parent' => 'test.example2', 'weight' => 2)), 4 => MenuLinkMock::create(array('id' => 'test.example4', 'route_name' => 'example4', 'title' => 'qux', 'parent' => 'test.example3', 'weight' => 3)), 5 => MenuLinkMock::create(array('id' => 'test.example5', 'route_name' => 'example5', 'title' => 'foofoo', 'parent' => '', 'expanded' => TRUE, 'weight' => 4)), 6 => MenuLinkMock::create(array('id' => 'test.example6', 'route_name' => '', 'url' => 'https://drupal.org/', 'title' => 'barbar', 'parent' => '', 'weight' => 5)), 7 => MenuLinkMock::create(array('id' => 'test.example7', 'route_name' => 'example7', 'title' => 'bazbaz', 'parent' => 'test.example5', 'weight' => 6)), 8 => MenuLinkMock::create(array('id' => 'test.example8', 'route_name' => 'example8', 'title' => 'quxqux', 'parent' => '', 'weight' => 7)));
     foreach ($links as $instance) {
         $this->menuLinkManager->addDefinition($instance->getPluginId(), $instance->getPluginDefinition());
     }
 }
Example #13
0
 /**
  * Submit handler for the menu overview form.
  *
  * This function takes great care in saving parent items first, then items
  * underneath them. Saving items in the incorrect order can break the tree.
  */
 protected function submitOverviewForm(array $complete_form, FormStateInterface $form_state)
 {
     // Form API supports constructing and validating self-contained sections
     // within forms, but does not allow to handle the form section's submission
     // equally separated yet. Therefore, we use a $form_state key to point to
     // the parents of the form section.
     $parents = $form_state['menu_overview_form_parents'];
     $input = NestedArray::getValue($form_state['input'], $parents);
     $form =& NestedArray::getValue($complete_form, $parents);
     // When dealing with saving menu items, the order in which these items are
     // saved is critical. If a changed child item is saved before its parent,
     // the child item could be saved with an invalid path past its immediate
     // parent. To prevent this, save items in the form in the same order they
     // are sent, ensuring parents are saved first, then their children.
     // See http://drupal.org/node/181126#comment-632270
     $order = is_array($input) ? array_flip(array_keys($input)) : array();
     // Update our original form with the new order.
     $form = array_intersect_key(array_merge($order, $form), $form);
     $fields = array('weight', 'parent', 'enabled');
     foreach (Element::children($form) as $id) {
         if (isset($form[$id]['#item'])) {
             $element = $form[$id];
             $updated_values = array();
             // Update any fields that have changed in this menu item.
             foreach ($fields as $field) {
                 if ($element[$field]['#value'] != $element[$field]['#default_value']) {
                     // Hidden is a special case, the form value needs to be reversed.
                     if ($field == 'enabled') {
                         $updated_values['hidden'] = $element['enabled']['#value'] ? 0 : 1;
                     } else {
                         $updated_values[$field] = $element[$field]['#value'];
                     }
                 }
             }
             if ($updated_values) {
                 // Use the ID from the actual plugin instance since the hidden value
                 // in the form could be tampered with.
                 $this->menuLinkManager->updateDefinition($element['#item']->link->getPLuginId(), $updated_values);
             }
         }
     }
 }
Example #14
0
 /**
  * Tests getCid()
  *
  * @covers ::getCid
  */
 public function testGetCid()
 {
     $data = $this->provider()[1];
     /** @var \Symfony\Component\HttpFoundation\Request $request */
     $request = $data[0];
     /** @var \Symfony\Component\Routing\Route $route */
     $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT);
     $route->setPath('/test/{b}/{a}');
     $request->attributes->get('_raw_variables')->add(['b' => 1, 'a' => 0]);
     $this->requestStack->push($request);
     $this->menuLinkManager->expects($this->any())->method('loadLinksbyRoute')->with('baby_llama')->will($this->returnValue($data[1]));
     $expected_link = $data[3];
     $expected_trail = $data[4];
     $expected_trail_ids = array_combine($expected_trail, $expected_trail);
     $this->menuLinkManager->expects($this->any())->method('getParentIds')->will($this->returnValueMap(array(array($expected_link->getPluginId(), $expected_trail_ids))));
     $this->assertSame($expected_trail_ids, $this->menuActiveTrail->getActiveTrailIds($data[2]));
     $this->cache->expects($this->once())->method('set')->with('active-trail:route:baby_llama:route_parameters:' . serialize(['a' => 0, 'b' => 1]));
     $this->lock->expects($this->any())->method('acquire')->willReturn(TRUE);
     $this->menuActiveTrail->destruct();
 }
Example #15
0
 /**
  * {@inheritdoc}
  */
 public function submit(array $form, FormStateInterface $form_state)
 {
     $form_state->setRedirect('menu_ui.overview_page');
     // Locked menus may not be deleted.
     if ($this->entity->isLocked()) {
         return;
     }
     // Delete all links to the overview page for this menu.
     // @todo Add a more generic helper function to the menu link plugin
     //   manager to remove links to a entity or other ID used as a route
     //   parameter that is being removed. Also, consider moving this to
     //   menu_ui.module as part of a generic response to entity deletion.
     //   https://www.drupal.org/node/2310329
     $menu_links = $this->menuLinkManager->loadLinksByRoute('menu_ui.menu_edit', array('menu' => $this->entity->id()), TRUE);
     foreach ($menu_links as $id => $link) {
         $this->menuLinkManager->removeDefinition($id);
     }
     // Delete the custom menu and all its menu links.
     $this->entity->delete();
     $t_args = array('%title' => $this->entity->label());
     drupal_set_message(t('The custom menu %title has been deleted.', $t_args));
     $this->logger('menu')->notice('Deleted custom menu %title and all its menu links.', $t_args);
 }
Example #16
0
 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $this->link = $this->menuLinkManager->resetLink($this->link->getPluginId());
     drupal_set_message($this->t('The menu link was reset to its default settings.'));
     $form_state->setRedirectUrl($this->getCancelUrl());
 }
Example #17
0
 /**
  * Builds a table row for the system modules page.
  *
  * @param array $modules
  *   The list existing modules.
  * @param \Drupal\Core\Extension\Extension $module
  *   The module for which to build the form row.
  * @param $distribution
  *
  * @return array
  *   The form row for the given module.
  */
 protected function buildRow(array $modules, Extension $module, $distribution)
 {
     // Set the basic properties.
     $row['#required'] = array();
     $row['#requires'] = array();
     $row['#required_by'] = array();
     $row['name']['#markup'] = $module->info['name'];
     $row['description']['#markup'] = $this->t($module->info['description']);
     $row['version']['#markup'] = $module->info['version'];
     // Generate link for module's help page, if there is one.
     $row['links']['help'] = array();
     if ($this->moduleHandler->moduleExists('help') && $module->status && in_array($module->getName(), $this->moduleHandler->getImplementations('help'))) {
         if ($this->moduleHandler->invoke($module->getName(), 'help', array('help.page.' . $module->getName(), $this->routeMatch))) {
             $row['links']['help'] = array('#type' => 'link', '#title' => $this->t('Help'), '#url' => Url::fromRoute('help.page', ['name' => $module->getName()]), '#options' => array('attributes' => array('class' => array('module-link', 'module-link-help'), 'title' => $this->t('Help'))));
         }
     }
     // Generate link for module's permission, if the user has access to it.
     $row['links']['permissions'] = array();
     if ($module->status && \Drupal::currentUser()->hasPermission('administer permissions') && in_array($module->getName(), $this->moduleHandler->getImplementations('permission'))) {
         $row['links']['permissions'] = array('#type' => 'link', '#title' => $this->t('Permissions'), '#url' => Url::fromRoute('user.admin_permissions'), '#options' => array('fragment' => 'module-' . $module->getName(), 'attributes' => array('class' => array('module-link', 'module-link-permissions'), 'title' => $this->t('Configure permissions'))));
     }
     // Generate link for module's configuration page, if it has one.
     $row['links']['configure'] = array();
     if ($module->status && isset($module->info['configure'])) {
         $route_parameters = isset($module->info['configure_parameters']) ? $module->info['configure_parameters'] : array();
         if ($this->accessManager->checkNamedRoute($module->info['configure'], $route_parameters, $this->currentUser)) {
             $links = $this->menuLinkManager->loadLinksByRoute($module->info['configure']);
             /** @var \Drupal\Core\Menu\MenuLinkInterface $link */
             $link = reset($links);
             // Most configure links have a corresponding menu link, though some just
             // have a route.
             if ($link) {
                 $description = $link->getDescription();
             } else {
                 $request = new Request();
                 $request->attributes->set('_route_name', $module->info['configure']);
                 $route_object = $this->routeProvider->getRouteByName($module->info['configure']);
                 $request->attributes->set('_route', $route_object);
                 $request->attributes->add($route_parameters);
                 $description = $this->titleResolver->getTitle($request, $route_object);
             }
             $row['links']['configure'] = array('#type' => 'link', '#title' => $this->t('Configure'), '#url' => Url::fromRoute($module->info['configure'], $route_parameters), '#options' => array('attributes' => array('class' => array('module-link', 'module-link-configure'), 'title' => $description)));
         }
     }
     // Present a checkbox for installing and indicating the status of a module.
     $row['enable'] = array('#type' => 'checkbox', '#title' => $this->t('Install'), '#default_value' => (bool) $module->status, '#disabled' => (bool) $module->status);
     // Disable the checkbox for required modules.
     if (!empty($module->info['required'])) {
         // Used when displaying modules that are required by the installation profile
         $row['enable']['#disabled'] = TRUE;
         $row['#required_by'][] = $distribution . (!empty($module->info['explanation']) ? ' (' . $module->info['explanation'] . ')' : '');
     }
     // Check the compatibilities.
     $compatible = TRUE;
     // Initialize an empty array of reasons why the module is incompatible. Add
     // each reason as a separate element of the array.
     $reasons = array();
     // Check the core compatibility.
     if ($module->info['core'] != \Drupal::CORE_COMPATIBILITY) {
         $compatible = FALSE;
         $reasons[] = $this->t('This version is not compatible with Drupal !core_version and should be replaced.', array('!core_version' => \Drupal::CORE_COMPATIBILITY));
     }
     // Ensure this module is compatible with the currently installed version of PHP.
     if (version_compare(phpversion(), $module->info['php']) < 0) {
         $compatible = FALSE;
         $required = $module->info['php'] . (substr_count($module->info['php'], '.') < 2 ? '.*' : '');
         $reasons[] = $this->t('This module requires PHP version @php_required and is incompatible with PHP version !php_version.', array('@php_required' => $required, '!php_version' => phpversion()));
     }
     // If this module is not compatible, disable the checkbox.
     if (!$compatible) {
         $status = implode(' ', $reasons);
         $row['enable']['#disabled'] = TRUE;
         $row['description']['#markup'] = $status;
         $row['#attributes']['class'][] = 'incompatible';
     }
     // If this module requires other modules, add them to the array.
     foreach ($module->requires as $dependency => $version) {
         if (!isset($modules[$dependency])) {
             $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">missing</span>)', array('@module' => Unicode::ucfirst($dependency)));
             $row['enable']['#disabled'] = TRUE;
         } elseif (empty($modules[$dependency]->hidden)) {
             $name = $modules[$dependency]->info['name'];
             // Disable the module's checkbox if it is incompatible with the
             // dependency's version.
             if ($incompatible_version = drupal_check_incompatibility($version, str_replace(\Drupal::CORE_COMPATIBILITY . '-', '', $modules[$dependency]->info['version']))) {
                 $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> version @version)', array('@module' => $name . $incompatible_version, '@version' => $modules[$dependency]->info['version']));
                 $row['enable']['#disabled'] = TRUE;
             } elseif ($modules[$dependency]->info['core'] != \Drupal::CORE_COMPATIBILITY) {
                 $row['#requires'][$dependency] = $this->t('@module (<span class="admin-missing">incompatible with</span> this version of Drupal core)', array('@module' => $name));
                 $row['enable']['#disabled'] = TRUE;
             } elseif ($modules[$dependency]->status) {
                 $row['#requires'][$dependency] = $this->t('@module', array('@module' => $name));
             } else {
                 $row['#requires'][$dependency] = $this->t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $name));
             }
         }
     }
     // If this module is required by other modules, list those, and then make it
     // impossible to disable this one.
     foreach ($module->required_by as $dependent => $version) {
         if (isset($modules[$dependent]) && empty($modules[$dependent]->info['hidden'])) {
             if ($modules[$dependent]->status == 1 && $module->status == 1) {
                 $row['#required_by'][$dependent] = $this->t('@module', array('@module' => $modules[$dependent]->info['name']));
                 $row['enable']['#disabled'] = TRUE;
             } else {
                 $row['#required_by'][$dependent] = $this->t('@module (<span class="admin-disabled">disabled</span>)', array('@module' => $modules[$dependent]->info['name']));
             }
         }
     }
     return $row;
 }
Example #18
0
 /**
  * {@inheritdoc}
  */
 public function submitConfigurationForm(array &$form, FormStateInterface $form_state)
 {
     $new_definition = $this->extractFormValues($form, $form_state);
     return $this->menuLinkManager->updateDefinition($this->menuLink->getPluginId(), $new_definition);
 }