/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form = array(); $form['#update_callbacks'] = array(); $form['update'] = array('#type' => 'checkboxes', '#title' => $this->t('Select the types of un-aliased paths for which to generate URL aliases'), '#options' => array(), '#default_value' => array()); $definitions = $this->aliasTypeManager->getVisibleDefinitions(); foreach ($definitions as $id => $definition) { $alias_type = $this->aliasTypeManager->createInstance($id); if ($alias_type instanceof AliasTypeBatchUpdateInterface) { $form['update']['#options'][$id] = $alias_type->getLabel(); } } $form['actions']['#type'] = 'actions'; $form['actions']['submit'] = array('#type' => 'submit', '#value' => $this->t('Update')); return $form; }
/** * {@inheritDoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $options = []; foreach ($this->manager->getVisibleDefinitions() as $plugin_id => $plugin_definition) { $options[$plugin_id] = $plugin_definition['label']; } $form['type'] = ['#type' => 'select', '#title' => $this->t('Pattern type'), '#default_value' => $this->entity->getType(), '#options' => $options, '#required' => TRUE, '#limit_validation_errors' => array(array('type')), '#submit' => array('::submitSelectType'), '#executes_submit_callback' => TRUE, '#ajax' => array('callback' => '::ajaxReplacePatternForm', 'wrapper' => 'pathauto-pattern', 'method' => 'replace')]; $form['pattern_container'] = ['#type' => 'container', '#prefix' => '<div id="pathauto-pattern">', '#suffix' => '</div>']; // if there is no type yet, stop here. if ($this->entity->getType()) { $alias_type = $this->entity->getAliasType(); $form['pattern_container']['pattern'] = array('#type' => 'textfield', '#title' => 'Path pattern', '#default_value' => $this->entity->getPattern(), '#size' => 65, '#maxlength' => 1280, '#element_validate' => array('token_element_validate', 'pathauto_pattern_validate'), '#after_build' => array('token_element_validate'), '#token_types' => $alias_type->getTokenTypes(), '#min_tokens' => 1, '#required' => TRUE); // Show the token help relevant to this pattern type. $form['pattern_container']['token_help'] = array('#theme' => 'token_tree_link', '#token_types' => $alias_type->getTokenTypes()); // Expose bundle and language conditions. if ($alias_type->getDerivativeId() && ($entity_type = $this->entityTypeManager->getDefinition($alias_type->getDerivativeId()))) { $default_bundles = []; $default_languages = []; foreach ($this->entity->getSelectionConditions() as $condition_id => $condition) { if (in_array($condition->getPluginId(), ['entity_bundle:' . $entity_type->id(), 'node_type'])) { $default_bundles = $condition->getConfiguration()['bundles']; } elseif ($condition->getPluginId() == 'language') { $default_languages = $condition->getConfiguration()['langcodes']; } } if ($entity_type->hasKey('bundle') && ($bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type->id()))) { $bundle_options = []; foreach ($bundles as $id => $info) { $bundle_options[$id] = $info['label']; } $form['pattern_container']['bundles'] = array('#title' => $entity_type->getBundleLabel(), '#type' => 'checkboxes', '#options' => $bundle_options, '#default_value' => $default_bundles, '#description' => t('Check to which types this pattern should be applied. Leave empty to allow any.')); } if ($this->languageManager->isMultilingual() && $entity_type->isTranslatable()) { $language_options = []; foreach ($this->languageManager->getLanguages() as $id => $language) { $language_options[$id] = $language->getName(); } $form['pattern_container']['languages'] = array('#title' => $this->t('Languages'), '#type' => 'checkboxes', '#options' => $language_options, '#default_value' => $default_languages, '#description' => t('Check to which languages this pattern should be applied. Leave empty to allow any.')); } } } $form['label'] = array('#type' => 'textfield', '#title' => $this->t('Label'), '#maxlength' => 255, '#default_value' => $this->entity->label(), '#required' => TRUE); $form['id'] = array('#type' => 'machine_name', '#title' => $this->t('ID'), '#maxlength' => 255, '#default_value' => $this->entity->id(), '#required' => TRUE, '#disabled' => !$this->entity->isNew(), '#machine_name' => array('exists' => 'Drupal\\pathauto\\Entity\\PathautoPattern::load')); $form['status'] = ['#title' => $this->t('Enabled'), '#type' => 'checkbox', '#default_value' => $this->entity->status()]; return parent::buildForm($form, $form_state); }
/** * {@inheritdoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $form['delete'] = array('#type' => 'fieldset', '#title' => $this->t('Choose aliases to delete'), '#tree' => TRUE); // First we do the "all" case. $storage_helper = \Drupal::service('pathauto.alias_storage_helper'); $total_count = $storage_helper->countAll(); $form['delete']['all_aliases'] = array('#type' => 'checkbox', '#title' => $this->t('All aliases'), '#default_value' => FALSE, '#description' => $this->t('Delete all aliases. Number of aliases which will be deleted: %count.', array('%count' => $total_count))); // Next, iterate over all visible alias types. $definitions = $this->aliasTypeManager->getVisibleDefinitions(); foreach ($definitions as $id => $definition) { /** @var \Drupal\pathauto\AliasTypeInterface $alias_type */ $alias_type = $this->aliasTypeManager->createInstance($id); $count = $storage_helper->countBySourcePrefix($alias_type->getSourcePrefix()); $form['delete']['plugins'][$id] = array('#type' => 'checkbox', '#title' => (string) $definition['label'], '#default_value' => FALSE, '#description' => $this->t('Delete aliases for all @label. Number of aliases which will be deleted: %count.', array('@label' => (string) $definition['label'], '%count' => $count))); } // Warn them and give a button that shows we mean business. $form['warning'] = array('#value' => '<p>' . t('<strong>Note:</strong> there is no confirmation. Be sure of your action before clicking the "Delete aliases now!" button.<br />You may want to make a backup of the database and/or the url_alias table prior to using this feature.') . '</p>'); $form['buttons']['submit'] = array('#type' => 'submit', '#value' => $this->t('Delete aliases now!')); return $form; }