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
Comments
Comment #2
panchukComment #3
boddy commentedComment #6
panchukComment #8
panchuk