You are here

function xmlsitemap_form_alter in XML sitemap 2.x

Same name and namespace in other branches
  1. 8 xmlsitemap.module \xmlsitemap_form_alter()
  2. 6 xmlsitemap.module \xmlsitemap_form_alter()

Implements hook_form_alter().

File

./xmlsitemap.module, line 1531
xmlsitemap XML sitemap

Code

function xmlsitemap_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
  $form_object = $form_state
    ->getFormObject();
  if ($form_object instanceof ContentEntityFormInterface) {
    $entity = $form_object
      ->getEntity();

    // Some entity types use 'default' for add/edit forms.
    $operations = [
      'default',
      'edit',
    ];
    if ($entity
      ->getEntityTypeId() === 'user') {
      $operations[] = 'register';
    }
    if (in_array($form_object
      ->getOperation(), $operations, TRUE) && xmlsitemap_link_bundle_check_enabled($entity
      ->getEntityTypeId(), $entity
      ->bundle())) {
      xmlsitemap_add_form_link_options($form, $entity
        ->getEntityTypeId(), $entity
        ->bundle(), $entity
        ->id());
      $form['xmlsitemap']['#weight'] = 10;
    }
  }
}