/** * Returns instance of the layout plugin used by this page variant. * * @return \Drupal\layout_plugin\Plugin\Layout\LayoutInterface * Layout plugin instance. */ public function getLayout() { if (!isset($this->layout)) { $this->layout = Layout::layoutPluginManager()->createInstance($this->configuration['layout'], array()); } return $this->layout; }
/** * Gets Display Suite layouts. */ public static function getLayouts() { static $layouts = FALSE; if (!$layouts) { $layouts = Layout::layoutPluginManager()->getDefinitions(); } return $layouts; }
/** * Render API callback: builds the layout settings elements. */ public function layoutSettingsProcessCallback(array &$element, FormStateInterface $form_state, array &$complete_form) { $parents_base = $element['#parents']; $layout_parent = array_merge($parents_base, ['layout']); $layout_settings_parent = array_merge($parents_base, ['layout_settings']); $settings_element =& $element['layout_settings_wrapper']['layout_settings']; // Set the #parents on the layout_settings so they end up as a sibling of // layout. $layout_settings_parents = array_merge($element['#parents'], ['layout_settings']); $settings_element['#parents'] = $layout_settings_parents; $settings_element['#tree'] = TRUE; // Get the layout name in a way that works regardless of whether we're // getting the value via AJAX or not. $layout_name = NestedArray::getValue($form_state->getUserInput(), $layout_parent) ?: $element['layout']['#default_value']; // Place the layout settings on the form if a layout is selected. if ($layout_name) { $layout = Layout::layoutPluginManager()->createInstance($layout_name, $form_state->getValue($layout_settings_parent, $this->configuration['layout_settings'] ?: [])); $settings_element = $layout->buildConfigurationForm($settings_element, $form_state); } // Store the array parents for our element so that we can use it to pull out // the layout settings in the validate and submit functions. $complete_form['#variant_array_parents'] = $element['#array_parents']; return $element; }