/** * 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. * * @return array * The form structure. */ public function buildForm(array $form, FormStateInterface $form_state, $name = null) { $sitemap = \Drupal::service('custom_sitemap.sitemap'); $custom_links = $sitemap->get_custom_links(); $form['#title'] = $this->t('Add new custom link'); $form['name'] = array('#type' => 'textfield', '#title' => $this->t('Machine name'), '#description' => $this->t('A unique machine-readable name for this content type. It must only contain lowercase letters, numbers, and underscores.'), '#required' => TRUE); $form['path'] = array('#type' => 'textfield', '#title' => $this->t('Path'), '#required' => TRUE, '#default_value' => $name !== null && array_key_exists($name, $custom_links) ? $custom_links[$name]['path'] : null); $form['index'] = array('#type' => 'checkbox', '#title' => $this->t('Include in sitemap'), '#default_value' => $name !== null && array_key_exists($name, $custom_links) && $custom_links[$name]['index']); $form['priority'] = array('#type' => 'select', '#title' => $this->t('Priority'), '#options' => SitemapGenerator::get_priority_select_values(), '#default_value' => $name !== null && array_key_exists($name, $custom_links) ? $custom_links[$name]['priority'] : SitemapGenerator::PRIORITY_DEFAULT); $form = parent::buildForm($form, $form_state); $form['actions']['submit']['#value'] = $this->t('Save link'); return $form; }
/** * @param array $form * @param string $entity_type * @param Vocabulary[] | NodeType[] $items * @param array $config */ private function setEntityTypeDetailForm(&$form, $entity_type, $items, $config) { foreach ($items as $machine_name => $item) { $form[$entity_type]["{$entity_type}-{$machine_name}"] = array('#type' => 'fieldset', '#title' => $item->label(), "{$entity_type}-{$machine_name}-index" => array('#type' => 'checkbox', '#title' => $this->t('Include in sitemap'), '#default_value' => array_key_exists($machine_name, $config) && $config[$machine_name]['index'] == 1), "{$entity_type}-{$machine_name}-priority" => array('#type' => 'select', '#title' => $this->t('Priority'), '#options' => SitemapGenerator::get_priority_select_values(), '#default_value' => array_key_exists($machine_name, $config) ? $config[$machine_name]['priority'] : SitemapGenerator::PRIORITY_DEFAULT)); } }