/** * {@inheritdoc} */ public function buildForm(array $form, array &$form_state, PageInterface $page = NULL, $page_variant_id = NULL, $layout_region_id = NULL, $block_id = NULL) { $this->page = $page; $this->displayVariant = $this->page->getVariant($page_variant_id); $this->displayVariant->setExecutable($page->getExecutable()); $this->layoutRegion = $this->displayVariant->getLayoutRegion($layout_region_id); $this->block = $this->prepareBlock($block_id); $form['#tree'] = TRUE; $form['settings'] = $this->block->buildConfigurationForm(array(), $form_state); $form['settings']['id'] = array('#type' => 'value', '#value' => $this->block->getPluginId()); // @note: we removed the region widget as it is implicit in URL. if ($this->block instanceof ContextAwarePluginInterface) { $form['context_assignments'] = $this->addContextAssignmentElement($this->block, $this->displayVariant->getContexts()); } $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->submitText(), '#button_type' => 'primary'); if ($this->getRequest()->isXmlHttpRequest()) { $form['actions']['submit']['#ajax'] = array('callback' => array($this, 'submitForm')); } return $form; }
/** * Converts a BlockPluginInterface to a minimal array (id, label, weight and region/region) * * @param BlockPluginInterface $block * @return array */ public static function blockToArray(BlockPluginInterface $block) { $config = $block->getConfiguration(); $settings = isset($config['settings']) ? $config['settings'] : array(); $definition = $block->getPluginDefinition(); if (isset($config['label']) && !empty($config['label'])) { $label = $config['label']; } else { $label = isset($definition['admin_label']) ? $definition['admin_label'] : $block->getPluginId(); } return array('id' => $config['uuid'], 'label' => $label, 'weight' => isset($config['weight']) ? $config['weight'] : 0, 'region' => $config['region']); }