This module adds a toolbar that organizes the paragraph types alphabetically. This is useful when building large sites with many paragraph types.

Project link

https://www.drupal.org/project/paragraphs_toolbar

Git instructions

git clone --branch 8.x-1.x https://git.drupal.org/project/paragraphs_toolbar.git

Comments

oknate created an issue. See original summary.

avpaderno’s picture

Title: Paragraphs Toolbar » [D8] Paragraphs Toolbar
Issue summary: View changes
Issue tags: -Paragraphs
avpaderno’s picture

Status: Needs review » Needs work
  public static function create(ContainerInterface $container) {
    return new static(
      $container->get('toolbar.menu_tree'),
      $container->get('config.factory'),
      $container->get('current_user')
    );
  }

  /**
   * Hook bridge.
   *
   * @return array
   *   The devel toolbar items render array.
   *
   * @see hook_toolbar()
   */
  public function toolbar() {

    $menu_link_service = \Drupal::getContainer()->get('plugin.manager.menu.link');

    $menu_links = $menu_link_service->loadLinksByRoute('entity.paragraphs_type.collection');


    $link = $menu_links['entity.paragraphs_type.collection'];

    $build = [
      '#type' => 'container',
      '#attributes' => ['class' => 'toolbar-menu-administration'],
      '#attached' => ['library' => ['paragraphs_toolbar/paragraphs-toolbar']]
    ];

    $menu_parameters = new \Drupal\Core\Menu\MenuTreeParameters();
    $menu_parameters->setMaxDepth(4);
    $menu_parameters->setRoot($link->getPluginId());
    $menu_parameters->excludeRoot();
    $menu_tree_service = \Drupal::service('toolbar.menu_tree');
    $tree = $menu_tree_service->load('admin', $menu_parameters);

    $manipulators = [
      ['callable' => 'menu.default_tree_manipulators:checkAccess'],
      ['callable' => 'menu.default_tree_manipulators:generateIndexAndSort'],
    ];
    $tree = $menu_tree_service->transform($tree, $manipulators);

    $item = $menu_tree_service->build($tree);

    $build[] = $item;

    $items['paragraphs'] = [
      '#cache' => [
        'contexts' => ['user.permissions'],
      ],
    ];

    if ($this->account->hasPermission('administer paragraphs types')) {
      $items['paragraphs'] += [
        '#type' => 'toolbar_item',
        '#weight' => 998,
        'tab' => [
          '#type' => 'link',
          '#title' => $this->t('Paragraph Types'),
          '#url' => Url::fromRoute('entity.paragraphs_type.collection'),
          '#attributes' => [
            'title' => $this->t('Paragraph Types'),
            'class' => ['toolbar-icon', 'toolbar-icon-devel'],
          ],
        ],
        'tray' => [
          '#heading' => $this->t('Paragraph Types'),
          'paragraphs_menu' => $build,
        ],
      ];
    }

    return $items;
  }

Since the class is implementing ContainerInjectionInterface it should not use any Drupal static methods. The necessary services should be created in create(). Alternatively, the create() method should pass the $container variable to the class construction, and the services would be obtained with $this->container->get().

avpaderno’s picture

In the second case (the container passed to the class constructor), the following interfaces/traits would be helpful.

oknate’s picture

I have fixed the dependency injection. I added a new release https://www.drupal.org/project/paragraphs_toolbar/releases/8.x-1.2

oknate’s picture

Status: Needs work » Needs review
avpaderno’s picture

Issue summary: View changes

As side note, there isn't any need to create a new release every time the code is fixed: You can just commit the code in the branch. I guess the documentation for the application process needs to be clearer about that.

oknate’s picture

Yeah, since it worked and there was nothing critical, I suppose I didn't need to do a new release. I'm new to maintaining a module.

avpaderno’s picture

It's OK, oknate.

You can work on the branch for all the time of the application, even if there is anything serious that is reported. The application should not change how often new releases are created. I just wanted to point that out, since the documentation was not really clear about that.

avpaderno’s picture

Status: Needs review » Needs work
oknate’s picture

What a great tool. I have updated the module, so that it shows no errors on PAReview.

avpaderno’s picture

Status: Needs work » Needs review
avpaderno’s picture

Assigned: Unassigned » avpaderno

PAReview doesn't report any issue. I will make a manual review tomorrow.

avpaderno’s picture

Status: Needs review » Reviewed & tested by the community
/**
 * Implements hook_help().
 *
 * @inheritdoc
 */
function paragraphs_toolbar_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.paragraphs_toolbar':
      $text = file_get_contents(dirname(__FILE__) . '/README.md');
      if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
        return '<pre>' . $text . '</pre>';
      }
      else {
        // Use the Markdown filter to render the README.
        $filter_manager = \Drupal::service('plugin.manager.filter');
        $settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
        $config = ['settings' => $settings];
        $filter = $filter_manager->createInstance('markdown', $config);
        return $filter->process($text, 'en');
      }
  }
  return NULL;
}

@inheritdoc is not used with hooks, but if it would be used, it should be put between { and }.
The content of a file still need to be sanitized, when output with HTML markup.

I will approve the application this evening.

avpaderno’s picture

Status: Reviewed & tested by the community » Fixed

Thank you for your contribution!
I am going to update your account so you can opt into security advisory coverage now.
These are some recommended readings to help with excellent maintainership:

You can find more contributors chatting on the IRC #drupal-contribute channel. So, come hang out and stay involved.
Thank you, also, for your patience with the review process.
Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

I thank all the dedicated reviewers as well.

oknate’s picture

Thank you for your help.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.