- Issue created by @pbabin
- πΊπΈUnited States pbabin
One finally worked. I threw the following into a .module file. Very specific but may help others if they come across a similar situation where trying to implement layout_options using layout_paragraphs.
Chees.
/** * Implements hook_form_layout_paragraphs_component_form_alter(). */ function my_module_form_layout_paragraphs_component_form_alter(array &$form, FormStateInterface &$form_state) { // Get title of paragraph form. $paragraphType = $form["#title"]->getArguments()["@type"]; // Section one column limit options based on role. if ($paragraphType === 'Section') { $form['#after_build'][] = 'uclahs_custom_paragraph_after_build'; } } /** * After build callback for layout options in layout paragraph. * Extend and generalize as needed if future layout options restriction needed. * * @param array $element * The form element array. * @param \Drupal\Core\Form\FormStateInterface $form_state * The Form state. * * @return array * The modified form element array. */ function my_module_paragraph_after_build(array $element, FormStateInterface $form_state): array { $current_user = Drupal::currentUser(); $user_roles = $current_user->getRoles(); $needles = ['role_1', 'role_2', 'role_3']; if ($current_user->id() !== '1' && !array_intersect($needles, $user_roles)) { $element["layout_paragraphs"]["config"]["layout"]["background"]['#access'] = false; } return $element; }
- Status changed to Fixed
10 months ago 8:19pm 2 February 2024 - π«π·France Grimreaper France π«π·
Hi,
Nice that you found yourself your solution.
Yes, it is either custom plugin or a hook_form_alter.
Automatically closed - issue fixed for 2 weeks with no activity.