You are here

function xmlsitemap_form_alter in XML sitemap 8

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

Implements hook_form_alter().

File

./xmlsitemap.module, line 1571
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;
    }
  }
}