You are here

public function PathautoBulkUpdateForm::buildForm in Pathauto 8

Form constructor.

Parameters

array $form: An associative array containing the structure of the form.

\Drupal\Core\Form\FormStateInterface $form_state: The current state of the form.

Return value

array The form structure.

Overrides FormInterface::buildForm

File

src/Form/PathautoBulkUpdateForm.php, line 69

Class

PathautoBulkUpdateForm
Configure file system settings for this site.

Namespace

Drupal\pathauto\Form

Code

public function buildForm(array $form, FormStateInterface $form_state) {
  $form = [];
  $form['#update_callbacks'] = [];
  $form['update'] = [
    '#type' => 'checkboxes',
    '#title' => $this
      ->t('Select the types of paths for which to generate URL aliases'),
    '#options' => [],
    '#default_value' => [],
  ];
  $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['action'] = [
    '#type' => 'radios',
    '#title' => $this
      ->t('Select which URL aliases to generate'),
    '#options' => [
      static::ACTION_CREATE => $this
        ->t('Generate a URL alias for un-aliased paths only'),
    ],
    '#default_value' => static::ACTION_CREATE,
  ];
  $config = $this
    ->config('pathauto.settings');
  if ($config
    ->get('update_action') == PathautoGeneratorInterface::UPDATE_ACTION_NO_NEW) {

    // Existing aliases should not be updated.
    $form['warning'] = [
      '#markup' => $this
        ->t('<a href=":url">Pathauto settings</a> are set to ignore paths which already have a URL alias. You can only create URL aliases for paths having none.', [
        ':url' => Url::fromRoute('pathauto.settings.form')
          ->toString(),
      ]),
    ];
  }
  else {
    $form['action']['#options'][static::ACTION_UPDATE] = $this
      ->t('Update the URL alias for paths having an old URL alias');
    $form['action']['#options'][static::ACTION_ALL] = $this
      ->t('Regenerate URL aliases for all paths');
  }
  $form['actions']['#type'] = 'actions';
  $form['actions']['submit'] = [
    '#type' => 'submit',
    '#value' => $this
      ->t('Update'),
  ];
  return $form;
}