Method GridstackContainer::view() can't attach external libraries

Created on 20 January 2023, almost 2 years ago
Updated 28 January 2023, almost 2 years ago

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

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡ΊπŸ‡¦Ukraine Panchuk Volyn, Lutsk

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024