Commit 7a5addda authored by catch's avatar catch
Browse files

Issue #3021804 by andypost, scott_euser, YurkinPark, mrinalini9, voleger,...

Issue #3021804 by andypost, scott_euser, YurkinPark, mrinalini9, voleger, Lendude, longwave: Remove optional dependency on menu_ui module in \Drupal\views\Plugin\views\wizard\WizardPluginBase
parent f8dbc98a
Loading
Loading
Loading
Loading
+11 −3
Changes for core/modules/node/src/Plugin/views/wizard/Node.php: 11 added lines, 3 removed lines.
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
use Drupal\views\Plugin\views\wizard\WizardPluginBase;
use Symfony\Component\DependencyInjection\ContainerInterface;

@@ -61,9 +62,15 @@ class Node extends WizardPluginBase {
   *   The entity display repository service.
   * @param \Drupal\Core\Entity\EntityFieldManagerInterface $entity_field_manager
   *   The entity field manager.
   * @param \Drupal\Core\Menu\MenuParentFormSelectorInterface $parent_form_selector
   *   The parent form selector service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, EntityDisplayRepositoryInterface $entity_display_repository, EntityFieldManagerInterface $entity_field_manager) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $bundle_info_service);
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, EntityDisplayRepositoryInterface $entity_display_repository, EntityFieldManagerInterface $entity_field_manager, MenuParentFormSelectorInterface $parent_form_selector = NULL) {
    if (!$parent_form_selector) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $parent_form_selector argument is deprecated in drupal:9.3.0 and the $parent_form_selector argument will be required in drupal:10.0.0. See https://www.drupal.org/node/3027559', E_USER_DEPRECATED);
      $parent_form_selector = \Drupal::service('menu.parent_form_selector');
    }
    parent::__construct($configuration, $plugin_id, $plugin_definition, $bundle_info_service, $parent_form_selector);

    $this->entityDisplayRepository = $entity_display_repository;
    $this->entityFieldManager = $entity_field_manager;
@@ -79,7 +86,8 @@ public static function create(ContainerInterface $container, array $configuratio
      $plugin_definition,
      $container->get('entity_type.bundle.info'),
      $container->get('entity_display.repository'),
      $container->get('entity_field.manager')
      $container->get('entity_field.manager'),
      $container->get('menu.parent_form_selector')
    );
  }

+19 −15
Changes for core/modules/views/src/Plugin/views/display/Page.php: 19 added lines, 15 removed lines.
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
use Drupal\Component\Utility\Xss;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Routing\RouteProviderInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -49,6 +50,13 @@ class Page extends PathPluginBase {
   */
  protected $menuStorage;

  /**
   * The parent form selector service.
   *
   * @var \Drupal\Core\Menu\MenuParentFormSelectorInterface
   */
  protected $parentFormSelector;

  /**
   * Constructs a Page object.
   *
@@ -64,10 +72,17 @@ class Page extends PathPluginBase {
   *   The state key value store.
   * @param \Drupal\Core\Entity\EntityStorageInterface $menu_storage
   *   The menu storage.
   * @param \Drupal\Core\Menu\MenuParentFormSelectorInterface $parent_form_selector
   *   The parent form selector service.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, EntityStorageInterface $menu_storage) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, RouteProviderInterface $route_provider, StateInterface $state, EntityStorageInterface $menu_storage, MenuParentFormSelectorInterface $parent_form_selector = NULL) {
    parent::__construct($configuration, $plugin_id, $plugin_definition, $route_provider, $state);
    $this->menuStorage = $menu_storage;
    if (!$parent_form_selector) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $parent_form_selector argument is deprecated in drupal:9.3.0 and the $parent_form_selector argument will be required in drupal:10.0.0. See https://www.drupal.org/node/3027559', E_USER_DEPRECATED);
      $parent_form_selector = \Drupal::service('menu.parent_form_selector');
    }
    $this->parentFormSelector = $parent_form_selector;
  }

  /**
@@ -80,7 +95,8 @@ public static function create(ContainerInterface $container, array $configuratio
      $plugin_definition,
      $container->get('router.route_provider'),
      $container->get('state'),
      $container->get('entity_type.manager')->getStorage('menu')
      $container->get('entity_type.manager')->getStorage('menu'),
      $container->get('menu.parent_form_selector')
    );
  }

@@ -311,11 +327,9 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
          '#description' => $this->t('If selected and this menu link has children, the menu will always appear expanded.'),
        ];

        // Only display the parent selector if Menu UI module is enabled.
        $menu_parent = $menu['menu_name'] . ':' . $menu['parent'];
        if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
        $menu_link = 'views_view:views.' . $form_state->get('view')->id() . '.' . $form_state->get('display_id');
          $form['menu']['parent'] = \Drupal::service('menu.parent_form_selector')->parentSelectElement($menu_parent, $menu_link);
        $form['menu']['parent'] = $this->parentFormSelector->parentSelectElement($menu_parent, $menu_link);
        $form['menu']['parent'] += [
          '#title' => $this->t('Parent'),
          '#description' => $this->t('The maximum depth for a link and all its children is fixed. Some menu links may not be available as parents if selecting them would exceed this limit.'),
@@ -331,16 +345,6 @@ public function buildOptionsForm(&$form, FormStateInterface $form_state) {
            ],
          ],
        ];
        }
        else {
          $form['menu']['parent'] = [
            '#type' => 'value',
            '#value' => $menu_parent,
          ];
          $form['menu']['markup'] = [
            '#markup' => $this->t('Menu selection requires the activation of Menu UI module.'),
          ];
        }
        $form['menu']['weight'] = [
          '#title' => $this->t('Weight'),
          '#type' => 'textfield',
+20 −16
Changes for core/modules/views/src/Plugin/views/wizard/WizardPluginBase.php: 20 added lines, 16 removed lines.
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@
use Drupal\Core\Entity\EntityPublishedInterface;
use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Menu\MenuParentFormSelectorInterface;
use Drupal\Core\Url;
use Drupal\views\Entity\View;
use Drupal\views\Views;
@@ -116,6 +117,13 @@ abstract class WizardPluginBase extends PluginBase implements WizardInterface {
   */
  protected $bundleInfoService;

  /**
   * The parent form selector service.
   *
   * @var \Drupal\Core\Menu\MenuParentFormSelectorInterface
   */
  protected $parentFormSelector;

  /**
   * {@inheritdoc}
   */
@@ -124,19 +132,26 @@ public static function create(ContainerInterface $container, array $configuratio
      $configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('entity_type.bundle.info')
      $container->get('entity_type.bundle.info'),
      $container->get('menu.parent_form_selector')
    );
  }

  /**
   * Constructs a WizardPluginBase object.
   */
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service) {
  public function __construct(array $configuration, $plugin_id, $plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, MenuParentFormSelectorInterface $parent_form_selector = NULL) {
    parent::__construct($configuration, $plugin_id, $plugin_definition);

    $this->bundleInfoService = $bundle_info_service;
    $this->base_table = $this->definition['base_table'];

    if (!$parent_form_selector) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $parent_form_selector argument is deprecated in drupal:9.3.0 and the $parent_form_selector argument will be required in drupal:10.0.0. See https://www.drupal.org/node/3027559', E_USER_DEPRECATED);
      $parent_form_selector = \Drupal::service('menu.parent_form_selector');
    }
    $this->parentFormSelector = $parent_form_selector;

    $entity_types = \Drupal::entityTypeManager()->getDefinitions();
    foreach ($entity_types as $entity_type_id => $entity_type) {
      if (in_array($this->base_table, [$entity_type->getBaseTable(), $entity_type->getDataTable(), $entity_type->getRevisionTable(), $entity_type->getRevisionDataTable()], TRUE)) {
@@ -305,20 +320,9 @@ public function buildForm(array $form, FormStateInterface $form_state) {
      '#prefix' => '<div id="edit-page-link-properties-wrapper">',
      '#suffix' => '</div>',
    ];
    if (\Drupal::moduleHandler()->moduleExists('menu_ui')) {
      $menu_options = menu_ui_get_menus();
    }
    else {
      // These are not yet translated.
      $menu_options = menu_list_system_menus();
      foreach ($menu_options as $name => $title) {
        $menu_options[$name] = $this->t($title);
      }
    }
    $form['displays']['page']['options']['link_properties']['menu_name'] = [
    $form['displays']['page']['options']['link_properties']['parent'] = $this->parentFormSelector->parentSelectElement('admin:');
    $form['displays']['page']['options']['link_properties']['parent'] += [
      '#title' => $this->t('Menu'),
      '#type' => 'select',
      '#options' => $menu_options,
    ];
    $form['displays']['page']['options']['link_properties']['title'] = [
      '#title' => $this->t('Link text'),
@@ -1092,7 +1096,7 @@ protected function pageDisplayOptions(array $form, FormStateInterface $form_stat
    if (!empty($page['link'])) {
      $display_options['menu']['type'] = 'normal';
      $display_options['menu']['title'] = $page['link_properties']['title'];
      $display_options['menu']['menu_name'] = $page['link_properties']['menu_name'];
      list($display_options['menu']['menu_name'], $display_options['menu']['parent']) = explode(':', $page['link_properties']['parent'], 2);
    }
    return $display_options;
  }
+2 −1
Changes for core/modules/views/tests/src/Functional/Plugin/DisplayPageWebTest.php: 2 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ class DisplayPageWebTest extends ViewTestBase {
   *
   * @var array
   */
  protected static $modules = ['menu_ui', 'block', 'views_ui'];
  protected static $modules = ['block', 'views_ui'];

  /**
   * {@inheritdoc}
@@ -123,6 +123,7 @@ public function testPageDisplayMenu() {

    $menu_link = $this->cssSelect('nav.block-menu ul.menu a');
    $this->assertEquals('Test menu link', $menu_link[0]->getText());
    $this->container->get('module_installer')->install(['menu_ui', 'menu_link_content']);

    // Update the menu link.
    $this->drupalGet("admin/structure/menu/link/views_view:views.test_page_display_menu.page_3/edit");
+1 −1
Changes for core/modules/views/tests/src/Functional/Plugin/MenuLinkTest.php: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ class MenuLinkTest extends ViewTestBase {
    'views_ui',
    'user',
    'node',
    'menu_ui',
    'menu_link_content',
    'block',
  ];

Loading