Commit 4198b5c3 authored by Dave Reid's avatar Dave Reid Committed by Dave Reid

Issue #3017153 by Dave Reid, dpi: Fixed XML sitemap form fields should only be...

Issue #3017153 by Dave Reid, dpi: Fixed XML sitemap form fields should only be added to edit forms only.
parent 345f5193
......@@ -16,9 +16,9 @@ use Drupal\Component\Utility\UrlHelper;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Database\Query\AlterableInterface;
use Drupal\Core\Database\Query\Condition;
use Drupal\Core\Entity\ContentEntityFormInterface;
use Drupal\Core\Entity\ContentEntityInterface;
use Drupal\Core\Entity\ContentEntityTypeInterface;
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\Core\File\FileSystemInterface;
......@@ -1507,44 +1507,21 @@ function theme_xmlsitemap_content_settings_table(array $variables) {
return '<h4>' . $variables['build']['#title'] . '</h4>' . \Drupal::service('renderer')->render($variables['build']);
}
/**
* Returns the entity form for the given form.
*
* @param Drupal\Core\Form\FormStateInterface $form_state
* The form state array holding the entity form.
*
* @return \Drupal\Core\Entity\EntityFormInterface
* An instance of the entity form interface or FALSE if not an
* entity form.
*/
function xmlsitemap_form_controller(FormStateInterface $form_state) {
return (NULL != $form_state->getFormObject()) && $form_state->getFormObject() instanceof EntityForm ? $form_state->getFormObject() : FALSE;
}
/**
* Implements hook_form_alter().
*/
function xmlsitemap_form_alter(array &$form, FormStateInterface $form_state, $form_id) {
$form_controller = xmlsitemap_form_controller($form_state);
$entity = $form_controller ? $form_controller->getEntity() : NULL;
$entity_type = $entity ? $entity->getEntityTypeId() : NULL;
$bundle = $entity ? $entity->bundle() : NULL;
if (!$form_controller) {
return;
}
// If this entity/bundle can be included in sitemap alter the form.
if (\Drupal::config("xmlsitemap.settings.{$entity_type}.{$bundle}")->isNew()) {
return;
}
if ($form_controller->getOperation() == 'delete') {
return;
$form_object = $form_state->getFormObject();
if ($form_object instanceof ContentEntityFormInterface) {
$entity = $form_object->getEntity();
// Some entity types use 'default' for edit forms.
$has_edit_form = $entity->getEntityType()->hasHandlerClass('form', 'edit');
$operation = $has_edit_form ? 'edit' : 'default';
if ($form_object->getOperation() === $operation && 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;
}
}
xmlsitemap_add_form_link_options($form, $entity_type, $bundle, $entity->id());
$form['xmlsitemap']['#weight'] = 10;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment