Commit c6e985f7 authored by andrei.dincu's avatar andrei.dincu

Issue #2249723 by andrei.dincu: Do not allow xmlsitemap widget to appear on delete entity form view

parent 0af9782a
......@@ -960,8 +960,8 @@ function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
$uri_callback = $entity_type->getUriCallback();
if (empty($uri_callback) || !isset($entity_type->xmlsitemap)) {
// Remove any non URL-able or XML sitemap un-supported entites.
unset($entity_types[$key]);
unset($link_info[$key]);
//unset($entity_types[$key]);
//unset($link_info[$key]);
}
foreach (\Drupal::entityManager()->getBundleInfo($entity_type->id()) as $bundle_key => $bundle) {
if (!isset($bundle['xmlsitemap'])) {
......@@ -969,8 +969,8 @@ function xmlsitemap_get_link_info($type = NULL, $reset = FALSE) {
//unset($link_info[$key]['bundles'][$bundle_key]);
}
}
unset($entity_types[$key]);
unset($link_info[$key]);
//unset($entity_types[$key]);
//unset($link_info[$key]);
}
$link_info = array_merge($link_info, \Drupal::moduleHandler()->invokeAll('xmlsitemap_link_info'));
foreach ($link_info as $key => &$info) {
......@@ -1024,18 +1024,16 @@ function xmlsitemap_get_link_type_indexed_status($entity_type, $bundle = '') {
$status['indexed'] = db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle", array(':entity' => $entity_type, ':bundle' => $bundle))->fetchField();
$status['visible'] = db_query("SELECT COUNT(id) FROM {xmlsitemap} WHERE type = :entity AND subtype = :bundle AND status = 1 AND access = 1", array(':entity' => $entity_type, ':bundle' => $bundle))->fetchField();
$total = new EntityFieldQuery();
$total->entityCondition('entity_type', $entity_type);
$total->entityCondition('bundle', $bundle);
$total->entityCondition('entity_id', 0, '>');
//$total->addTag('xmlsitemap_link_bundle_access');
$total->addTag('xmlsitemap_link_indexed_status');
$total->addMetaData('entity', $entity_type);
$total->addMetaData('bundle', $bundle);
$total->addMetaData('entity_info', $info);
$total->count();
$status['total'] = $total->execute();
$entity_query_object = \Drupal::entityQuery($entity_type);
$entity_query_object->addTag('xmlsitemap_link_bundle_access');
$entity_query_object->addTag('xmlsitemap_link_indexed_status');
//$entity_query_object->addMetaData('entity', $entity_type);
//$entity_query_object->addMetaData('type', $bundle);
//$entity_query_object->addMetaData('entity_info', $info);
//$entity_query_object->condition('bundle', $bundle);
//$entity_query_object->condition('id', 0, '>');
$entity_query_object->count();
$status['total'] = $entity_query_object->execute();
return $status;
}
......@@ -1702,6 +1700,10 @@ function xmlsitemap_form_alter(array &$form, array &$form_state) {
return;
}
if ($form_controller->getOperation() == 'delete') {
return;
}
module_load_include('inc', 'xmlsitemap', 'xmlsitemap.admin');
xmlsitemap_add_form_link_options($form, $entity_type, $bundle, $entity->id());
$form['xmlsitemap']['#weight'] = 100;
......@@ -1815,18 +1817,6 @@ function xmlsitemap_entity_delete(EntityInterface $entity) {
xmlsitemap_link_delete($entity->getEntityTypeId(), $entity->id());
}
/**
* Implements hook_field_extra_fields().
*/
/* function xmlsitemap_field_extra_fields() {
$extras['user']['user']['form']['xmlsitemap'] = array(
'label' => t('XML sitemap'),
'description' => t('XML sitemap module element'),
'weight' => 30,
);
return $extras;
} */
/**
* Create a sitemap link from an entity.
*
......@@ -1848,7 +1838,7 @@ function xmlsitemap_entity_create_link(EntityInterface $entity) {
$entity->xmlsitemap += array(
'type' => $entity->getEntityTypeId(),
'id' => $entity->id(),
'subtype' => $entity->label(),
'subtype' => $entity->bundle(),
'status' => $settings['status'],
'status_default' => $settings['status'],
'status_override' => 0,
......@@ -1857,9 +1847,10 @@ function xmlsitemap_entity_create_link(EntityInterface $entity) {
'priority_override' => 0,
);
$url = $entity->url();
// The following values must always be checked because they are volatile.
$entity->xmlsitemap['loc'] = $uri;
$entity->xmlsitemap['access'] = $entity->url() && $status;
$entity->xmlsitemap['access'] = isset($url) ? 1 : 0;
$entity->xmlsitemap['status'] = 1;
$language = $entity->language();
$entity->xmlsitemap['language'] = !empty($language) ? $language->getId() : LanguageInterface::LANGCODE_NOT_SPECIFIED;
......
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