/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = $this->plugin->buildConfigurationForm($form, $form_state); $form['block_branding']['#type'] = 'details'; $form['block_branding']['#weight'] = 10; // Unset links to Site Information form, we can make these changes here. unset($form['block_branding']['use_site_name']['#description'], $form['block_branding']['use_site_slogan']['#description']); $site_config = $this->configFactory->getEditable('system.site'); $form['site_information'] = ['#type' => 'details', '#title' => t('Site details'), '#open' => TRUE]; $form['site_information']['site_name'] = ['#type' => 'textfield', '#title' => t('Site name'), '#default_value' => $site_config->get('name'), '#required' => TRUE]; $form['site_information']['site_slogan'] = ['#type' => 'textfield', '#title' => t('Slogan'), '#default_value' => $site_config->get('slogan'), '#description' => t("How this is used depends on your site's theme.")]; return $form; }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state, PageVariantInterface $page_variant = NULL, $block_id = NULL) { $this->pageVariant = $page_variant; $this->block = $this->prepareBlock($block_id); $form_state->set('page_variant_id', $page_variant->id()); $form_state->set('block_id', $this->block->getConfiguration()['uuid']); $form['#tree'] = TRUE; $form['settings'] = $this->block->buildConfigurationForm([], $form_state); $form['settings']['id'] = ['#type' => 'value', '#value' => $this->block->getPluginId()]; $form['region'] = ['#title' => $this->t('Region'), '#type' => 'select', '#options' => $this->getVariantPlugin()->getRegionNames(), '#default_value' => $this->getVariantPlugin()->getRegionAssignment($this->block->getConfiguration()['uuid']), '#required' => TRUE]; if ($this->block instanceof ContextAwarePluginInterface) { $form['context_mapping'] = $this->addContextAssignmentElement($this->block, $this->pageVariant->getContexts()); } $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->submitText(), '#button_type' => 'primary']; return $form; }
/** * Form constructor. * * @param array $form * An associative array containing the structure of the form. * @param \Drupal\Core\Form\FormStateInterface $form_state * The current state of the form. * @param null $block_id * The id of the block to place. * * @return array The form structure. * The form structure. */ public function buildForm(array $form, FormStateInterface $form_state, $block_id = NULL) { $this->entityLayout = $this->getEntityLayoutFromRouteMatch(); $this->block = $this->prepareBlock($block_id); // Some blocks require contexts, set a temporary value with gathered // contextual values. $form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts()); $form['#tree'] = TRUE; $form['settings'] = $this->block->buildConfigurationForm([], $form_state); $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->t('Save block'), '#button_type' => 'primary']; return $form; }
/** * Form constructor. * * @param array $form * An associative array containing the structure of the form. * @param FormStateInterface $form_state * The current state of the form. * @param MegaMenuInterface $mega_menu * The mega menu the block should be added to. * @param string|null $block_id * The ID of the block to show a configuration form for. * * @return array */ public function buildForm(array $form, FormStateInterface $form_state, Request $request = NULL, MegaMenuInterface $mega_menu = NULL, $block_id = NULL) { $this->megaMenu = $mega_menu; // Get the query parameters needed. $form_state->set('link', $request->query->get('link')); $form_state->set('region', $request->query->get('region')); $this->block = $this->prepareBlock($form_state->get('link'), $block_id); // Some blocks require contexts, set a temporary value with gathered // contextual values. $form_state->setTemporaryValue('gathered_contexts', $this->contextRepository->getAvailableContexts()); $form['#tree'] = TRUE; $form['settings'] = $this->block->buildConfigurationForm([], $form_state); $form['actions']['submit'] = ['#type' => 'submit', '#value' => $this->getSubmitValue(), '#button_type' => 'primary']; return $form; }
/** * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { $form = $this->plugin->buildConfigurationForm([], $form_state); // Move the menu levels section to the bottom. $form['menu_levels']['#weight'] = 100; $form['entity_form'] = ['#type' => 'details', '#title' => $this->t('Edit menu %label', array('%label' => $this->entity->label())), '#open' => TRUE]; $form['entity_form'] += $this->getEntityForm($this->entity)->buildForm([], $form_state); // Print the menu link titles as text instead of a link. if (!empty($form['entity_form']['links']['links'])) { foreach (Element::children($form['entity_form']['links']['links']) as $child) { $title = $form['entity_form']['links']['links'][$child]['title'][1]['#title']; $form['entity_form']['links']['links'][$child]['title'][1] = ['#markup' => $title]; } } // Change the header text. $form['entity_form']['links']['links']['#header'][0] = $this->t('Link'); $form['entity_form']['links']['links']['#header'][1]['data'] = $this->t('On'); // Remove the label, ID, description, and buttons from the entity form. unset($form['entity_form']['label'], $form['entity_form']['id'], $form['entity_form']['description'], $form['entity_form']['actions']); // Since the overview form is further nested than expected, update the // #parents. See \Drupal\menu_ui\MenuForm::form(). $form_state->set('menu_overview_form_parents', ['settings', 'entity_form', 'links']); return $form; }