Problem/Motivation

Method GridstackContainer::view() can't attach external libraries. Due to the last changes added in #843c5b9b we have a possibility to alter the list of the griststack libraries providers. We need to update the view() method and replace hard-coded parts.

  /**
   * {@inheritdoc}
   */
  public function view(array &$build, Paragraph $paragraph, EntityViewDisplayInterface $display, $view_mode) {
    $libraries = ['paragraphs_gridstack/paragraphs_gridstack.base'];
    $settings = $paragraph->getBehaviorSetting($this->getPluginId(), 'settings', '');
    $column_options = $this->buildColumnsOptions(TRUE);

    if (empty($settings)) {
      return;
    }

    foreach ($settings as $breakpoint_name => $breakpoint_value) {
      foreach ($breakpoint_value as $name => $value) {
        $setting_name = substr($name, strlen($breakpoint_name) + 1);
        $attribute_name = 'data-' . preg_replace('~[\\\\/:*?"<>|._]~', '-', $name);
        switch ($setting_name) {
          case 'columns':
            $libraries[] = "paragraphs_gridstack/${value}";
            $build['#attributes'][$attribute_name] = $column_options[$value]['columns'];
            break;

          case 'storage':
            $build['#attributes'][$attribute_name] = $value;
            break;
        }
      }
    }
    $libraries = array_filter(array_unique($libraries));
    $attached_libraries = $build['#attached']['library'] ?? [];
    $build['#attached']['library'] = array_merge($libraries, $attached_libraries);
  }

Proposed resolution

1) Probably we can use the buildColumnsOptions() method to get the correct name of the library.

Remaining tasks

1) Plan and suggest some solution for this problem.
2) Replace 'hardcode'.
3) Add more details for 'foreach' used in the view() method.
4) Replace assert() method

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Panchuk created an issue. See original summary.

panchuk’s picture

Issue tags: +LutskGCW23
boddy’s picture

Assigned: Unassigned » boddy

  • boddy committed 3b1492e9 on 1.0.x
    Issue #3335173 Added logger, removed assert(), added logging to...

panchuk’s picture

Assigned: boddy » panchuk
Status: Active » Needs review

  • Panchuk committed e6e3598e on 1.0.x authored by boddy
    Issue #3335173 by boddy, Panchuk: Method GridstackContainer::view() can'...
panchuk’s picture

Assigned: panchuk » Unassigned
Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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