/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('pathauto.pattern'); $definitions = $this->aliasTypeManager->getDefinitions(); foreach ($definitions as $id => $definition) { $config->set('patterns.' . $id, $form_state->getValue($id)); } $config->save(); parent::submitForm($form, $form_state); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { if ($form_state->getValue(['delete', 'all_aliases'])) { db_delete('url_alias')->execute(); drupal_set_message($this->t('All of your path aliases have been deleted.')); } foreach (array_keys(array_filter($form_state->getValue(['delete', 'plugins']))) as $id) { /** @var \Drupal\pathauto\AliasTypeInterface $alias_type */ $alias_type = $this->aliasTypeManager->createInstance($id); db_delete('url_alias')->condition('source', db_like($alias_type->getSourcePrefix()) . '%', 'LIKE')->execute(); drupal_set_message(t('All of your %label path aliases have been deleted.', array('%label' => $alias_type->getLabel()))); } $form_state->setRedirect('pathauto.bulk.update.form'); }
/** * {@inheritdoc} */ public function submitForm(array &$form, FormStateInterface $form_state) { $storage_helper = \Drupal::service('pathauto.alias_storage_helper'); if ($form_state->getValue(['delete', 'all_aliases'])) { $storage_helper->deleteAll(); drupal_set_message($this->t('All of your path aliases have been deleted.')); } foreach (array_keys(array_filter($form_state->getValue(['delete', 'plugins']))) as $id) { $alias_type = $this->aliasTypeManager->createInstance($id); $storage_helper->deleteBySourcePrefix((string) $alias_type->getSourcePrefix()); drupal_set_message($this->t('All of your %label path aliases have been deleted.', array('%label' => $alias_type->getLabel()))); } $form_state->setRedirect('pathauto.admin.delete'); }
/** * {@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 submitForm(array &$form, FormStateInterface $form_state) { $config = $this->config('pathauto.settings'); $form_state->cleanValues(); $original_entity_types = $config->get('enabled_entity_types'); foreach ($form_state->getValues() as $key => $value) { if ($key == 'enabled_entity_types') { $enabled_entity_types = []; foreach ($value as $entity_type_id => $enabled) { $field_definitions = $this->entityFieldManager->getBaseFieldDefinitions($entity_type_id); // Verify that the entity type is enabled and that it is not defined // or defined by us before adding it to the configuration, so that // we do not store an entity type that cannot be enabled or disabled. if ($enabled && (!isset($field_definitions['path']) || $field_definitions['path']->getProvider() === 'pathauto')) { $enabled_entity_types[] = $entity_type_id; } } $value = $enabled_entity_types; } $config->set($key, $value); } $config->save(); // Clear cached field definitions if the values are changed. if ($original_entity_types != $config->get('enabled_entity_types')) { $this->entityFieldManager->clearCachedFieldDefinitions(); $this->aliasTypeManager->clearCachedDefinitions(); } parent::submitForm($form, $form_state); }
/** * {@inheritDoc} */ public function buildForm(array $form, FormStateInterface $form_state) { $options = []; foreach ($this->manager->getDefinitions() 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); // 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); }