...
 
Commits (3)
......@@ -103,42 +103,42 @@ function simple_sitemap_entity_form_submit($form, FormStateInterface &$form_stat
/** @var \Drupal\simple_sitemap\Simplesitemap $generator */
$generator = \Drupal::service('simple_sitemap.generator');
// Only save other values if indexing is enabled.
if ($settings['index'] = (bool) $values['simple_sitemap_index_content']) {
$settings['priority'] = $values['simple_sitemap_priority'];
$settings['changefreq'] = $values['simple_sitemap_changefreq'];
$settings['include_images'] = (bool) $values['simple_sitemap_include_images'];
}
// Deleting bundle settings for old bundle.
// See SimplesitemapEntitiesForm::submitForm().
// todo: Not necessary once https://www.drupal.org/project/simple_sitemap/issues/3014649 is implemented.
if (isset($form['simple_sitemap']['simple_sitemap_variant']['#default_value'])) {
$old_variant = $form['simple_sitemap']['simple_sitemap_variant']['#default_value'];
if ($old_variant !== $values['simple_sitemap_variant']) {
$generator->setVariants($old_variant)->removeBundleSettings($f->getEntityTypeId(), $f->getBundleName());
foreach ($generator->getSitemapManager()->getSitemapVariants(NULL, FALSE) as $variant => $definition) {
if (isset($values['index_' . $variant])) { // Variants may have changed since form load.
$settings = [
'index' => (bool) $values['index_' . $variant],
'priority' => $values['priority_' . $variant],
'changefreq' => $values['changefreq_' . $variant],
'include_images' => (bool) $values['include_images_' . $variant],
];
$generator->setVariants($variant);
switch ($f->getEntityCategory()) {
case 'bundle':
$generator->setBundleSettings($f->getEntityTypeId(),
!empty($f->getBundleName()) ? $f->getBundleName() : $f->getFormEntityId(),
$settings
);
if (empty($settings['index'])) {
$generator->removeEntityInstanceSettings($f->getEntityTypeId(), $f->getInstanceId());
}
break;
case 'instance':
$generator->setEntityInstanceSettings($f->getEntityTypeId(),
!empty($f->getInstanceId()) ? $f->getInstanceId() : $f->getFormEntityId(),
$settings
);
break;
}
}
}
switch ($f->getEntityCategory()) {
case 'bundle':
$generator->setVariants($values['simple_sitemap_variant'])
->setBundleSettings($f->getEntityTypeId(),
!empty($f->getBundleName()) ? $f->getBundleName() : $f->getFormEntityId(),
$settings
);
break;
case 'instance':
$generator->setVariants($values['simple_sitemap_variant'])
->setEntityInstanceSettings($f->getEntityTypeId(),
!empty($f->getInstanceId()) ? $f->getInstanceId() : $f->getFormEntityId(),
$settings
);
break;
}
// Regenerate sitemaps according to user setting.
if ($values['simple_sitemap_regenerate_now']) {
$generator->rebuildQueue()->generateSitemap();
......
......@@ -91,6 +91,8 @@ class SimplesitemapController extends ControllerBase {
'[priority]' => $this->t('Priority'),
'[translation-set]' => $this->t('Translation set'),
'[images]' => $this->t('Images'),
'[image-title]' => $this->t('Title'),
'[image-caption]' => $this->t('Caption'),
'[jquery]' => base_path() . 'core/assets/vendor/jquery/jquery.min.js',
'[jquery-tablesorter]' => base_path() . $module_path . '/xsl/jquery.tablesorter.min.js',
'[parser-date-iso8601]' => base_path() . $module_path . '/xsl/parser-date-iso8601.min.js',
......
......@@ -97,17 +97,16 @@ class FormHelper {
'never',
];
/**
* @var array
*/
protected static $valuesToCheck = [
'simple_sitemap_variant',
'simple_sitemap_index_content',
'simple_sitemap_priority',
'simple_sitemap_changefreq',
'simple_sitemap_include_images',
'simple_sitemap_regenerate_now',
];
// /**
// * @var array
// */
// protected static $valuesToCheck = [
// 'simple_sitemap_index',
// 'simple_sitemap_priority',
// 'simple_sitemap_changefreq',
// 'simple_sitemap_include_images',
// 'simple_sitemap_regenerate_now',
// ];
/**
* FormHelper constructor.
......@@ -228,16 +227,6 @@ class FormHelper {
return FALSE;
}
// Do not alter the form, if sitemap is disabled for the entity type or
// bundle of this entity instance.
elseif ($this->getEntityCategory() === 'instance') {
if (NULL === $this->instanceSettings || !$this->generator
->setVariants(TRUE)
->bundleIsIndexed($this->getEntityTypeId(), $this->getBundleName())) {
return FALSE;
}
}
return TRUE;
}
......@@ -265,14 +254,21 @@ class FormHelper {
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*/
public function negotiateSettings() {
if ($this->getEntityCategory() === 'instance' && NULL !== $this->getInstanceId()) {
$this->settings = $this->generator->setVariants(TRUE)
->getEntityInstanceSettings($this->getEntityTypeId(), $this->getInstanceId());
$this->settings = $this->generator->setVariants(TRUE)
->getBundleSettings($this->getEntityTypeId(), $this->getBundleName(), TRUE, TRUE);
if ($this->getEntityCategory() === 'instance') {
//todo Should spit out variant => settings and not just settings; to do this, alter getEntityInstanceSettings() to include 'multiple variants' option.
}
else {
$this->settings = $this->generator->setVariants(TRUE)
->getBundleSettings($this->getEntityTypeId(), $this->getBundleName(), TRUE, TRUE);
foreach ($this->settings as $variant_name => $settings) {
if (NULL !== $instance_id = $this->getInstanceId()) {
$this->settings[$variant_name] = $this->generator->setVariants($variant_name)
->getEntityInstanceSettings($this->getEntityTypeId(), $instance_id);
}
$this->settings[$variant_name]['bundle_settings'] = $settings;
}
}
return $this;
......@@ -282,15 +278,17 @@ class FormHelper {
* @param $form_fragment
* @param bool $multiple
* @return $this
*
* @todo Update JS according to new form logic.
* @todo Update SimplesitemapEntitiesForm.
* @todo Update tests.
*/
public function displayEntitySettings(&$form_fragment, $multiple = FALSE) {
$prefix = $multiple ? $this->getEntityTypeId() . '_' : '';
$bundle_name = !empty($this->getBundleName()) ? $this->getBundleName() : $this->t('undefined');
// Simplesitemap::supplementDefaultSettings('entity', $settings); // todo: necessary?
// Variants
$variants = $this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE);
foreach ($variants as $variant => $definition) {
foreach ($this->generator->getSitemapManager()->getSitemapVariants(NULL, FALSE) as $variant => $definition) {
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant] = [
'#type' => 'details',
'#title' => '<em>' . $definition['label'] . '</em>',
......@@ -298,115 +296,90 @@ class FormHelper {
// '#description' => !empty($type_definition['description']) ? '<div class="description">' . $type_definition['description'] . '</div>' : '',
];
// Disable fields of entity instance whose bundle is not indexed.
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['#disabled'] = $this->getEntityCategory() === 'instance' && empty($this->settings[$variant]['bundle_settings']['index']);
// Index
if (!$multiple) {
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['index_content'] = [
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['index_' . $variant] = [
'#type' => 'radios',
'#default_value' => (int) $this->settings[$variant]['index'],
'#options' => [
0 => $this->getEntityCategory() === 'instance'
$this->getEntityCategory() === 'instance'
? $this->t('Do not index this @bundle entity', ['@bundle' => $bundle_name])
: $this->t('Do not index entities of this type'),
1 => $this->getEntityCategory() === 'instance'
$this->getEntityCategory() === 'instance'
? $this->t('Index this @bundle entity', ['@bundle' => $bundle_name])
: $this->t('Index entities of this type'),
],
];
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings[$variant]['index'])) {
$form_fragment[$prefix . 'simple_sitemap_index_content']['#options'][(int) $this->settings[$variant]['index']] .= ' <em>(' . $this->t('default') . ')</em>';
if ($this->getEntityCategory() === 'instance' && isset($this->settings[$variant]['bundle_settings']['index'])) {
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['index_' . $variant]['#options'][(int) $this->settings[$variant]['bundle_settings']['index']] .= ' <em>(' . $this->t('default') . ')</em>';
}
}
}
// $form_fragment[$prefix . 'simple_sitemap_variant'] = [
// '#type' => 'select',
// '#title' => $this->t('Sitemap variants'),
// '#description' => $this->t('The sitemap variants entities of this type are to be indexed in.'),
// '#options' => array_map(function($variants) { return $this->t($variants['label']); }, $variants),
// '#disabled' => $this->getEntityCategory() === 'instance',
// '#default_value' => $indexed_variants,
// ];
// Priority
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['priority_' . $variant] = [
'#type' => 'select',
'#title' => $this->t('Priority'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name])
: $this->t('The priority entities of this type will have in the eyes of search engine bots.'),
'#default_value' => $this->settings[$variant]['priority'],
'#options' => $this->getPrioritySelectValues(),
'#states' => [
'visible' => !$multiple
? [':input[name="' . 'index_' . $variant . '"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]], //todo
],
];
//
// // Variant
// $form_fragment[$prefix . 'simple_sitemap_variant'] = [
// '#type' => 'select',
// '#title' => $this->t('Sitemap variant'),
// '#description' => $this->t('The sitemap variant entities of this type are to be indexed in.'),
// '#options' => $this->getVariantSelectValues(),
// '#default_value' => $this->getVariantSelectValuesDefault($this->variant),
// '#states' => [
// 'visible' => !$multiple
// ? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
// : [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
// 'required' => !$multiple // todo Should implement server side validation on top of this.
// ? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
// : [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
// ],
// '#disabled' => $this->getEntityCategory() === 'instance',
// ];
/* // Priority
$form_fragment[$prefix . 'simple_sitemap_priority'] = [
'#type' => 'select',
'#title' => $this->t('Priority'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The priority this @bundle entity will have in the eyes of search engine bots.', ['@bundle' => $bundle_name])
: $this->t('The priority entities of this type will have in the eyes of search engine bots.'),
'#default_value' => $settings['priority'],
'#options' => $this->getPrioritySelectValues(),
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
];
if ($this->getEntityCategory() === 'instance' && isset($this->settings[$variant]['bundle_settings']['priority'])) {
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['priority_' . $variant]['#options'][$this->formatPriority($this->settings[$variant]['bundle_settings']['priority'])] .= ' (' . $this->t('default') . ')';
}
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['priority'])) {
$form_fragment[$prefix . 'simple_sitemap_priority']['#options'][$this->formatPriority($this->bundleSettings['priority'])] .= ' (' . $this->t('default') . ')';
}
// Changefreq
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['changefreq_' . $variant] = [
'#type' => 'select',
'#title' => $this->t('Change frequency'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The frequency with which this @bundle entity changes. Search engine bots may take this as an indication of how often to index it.', ['@bundle' => $bundle_name])
: $this->t('The frequency with which entities of this type change. Search engine bots may take this as an indication of how often to index them.'),
'#default_value' => $this->settings[$variant]['changefreq'],
'#options' => $this->getChangefreqSelectValues(),
'#states' => [
'visible' => !$multiple
? [':input[name="' . 'index_' . $variant . '"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]], //todo
],
];
// Changefreq
$form_fragment[$prefix . 'simple_sitemap_changefreq'] = [
'#type' => 'select',
'#title' => $this->t('Change frequency'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('The frequency with which this @bundle entity changes. Search engine bots may take this as an indication of how often to index it.', ['@bundle' => $bundle_name])
: $this->t('The frequency with which entities of this type change. Search engine bots may take this as an indication of how often to index them.'),
'#default_value' => $settings['changefreq'],
'#options' => $this->getChangefreqSelectValues(),
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
];
if ($this->getEntityCategory() === 'instance' && isset($this->settings[$variant]['bundle_settings']['changefreq'])) {
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['changefreq_' . $variant]['#options'][$this->settings[$variant]['bundle_settings']['changefreq']] .= ' (' . $this->t('default') . ')';
}
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['changefreq'])) {
$form_fragment[$prefix . 'simple_sitemap_changefreq']['#options'][$this->bundleSettings['changefreq']] .= ' (' . $this->t('default') . ')';
}
// Images
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['include_images_' . $variant] = [
'#type' => 'select',
'#title' => $this->t('Include images'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('Determines if images referenced by this @bundle entity should be included in the sitemap.', ['@bundle' => $bundle_name])
: $this->t('Determines if images referenced by entities of this type should be included in the sitemap.'),
'#default_value' => (int) $this->settings[$variant]['include_images'],
'#options' => [$this->t('No'), $this->t('Yes')],
'#states' => [
'visible' => !$multiple
? [':input[name="' . 'index_' . $variant . '"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]], //todo
],
];
// Images
$form_fragment[$prefix . 'simple_sitemap_include_images'] = [
'#type' => 'select',
'#title' => $this->t('Include images'),
'#description' => $this->getEntityCategory() === 'instance'
? $this->t('Determines if images referenced by this @bundle entity should be included in the sitemap.', ['@bundle' => $bundle_name])
: $this->t('Determines if images referenced by entities of this type should be included in the sitemap.'),
'#default_value' => (int) $settings['include_images'],
'#options' => [0 => $this->t('No'), 1 => $this->t('Yes')],
'#states' => [
'visible' => !$multiple
? [':input[name="' . $prefix . 'simple_sitemap_index_content"]' => ['value' => 1]]
: [':input[name="' . $prefix . 'enabled"]' => ['checked' => TRUE]],
],
];
if ($this->getEntityCategory() === 'instance' && isset($this->settings[$variant]['bundle_settings']['include_images'])) {
$form_fragment[$prefix . 'simple_sitemap_variant_' . $variant]['include_images_' . $variant]['#options'][(int) $this->settings[$variant]['bundle_settings']['include_images']] .= ' (' . $this->t('default') . ')';
}
if ($this->getEntityCategory() === 'instance' && isset($this->bundleSettings['include_images'])) {
$form_fragment[$prefix . 'simple_sitemap_include_images']['#options'][(int) $this->bundleSettings['include_images']] .= ' (' . $this->t('default') . ')';
}*/
}
return $this;
}
......@@ -520,14 +493,17 @@ class FormHelper {
* TRUE if simple_sitemap form values have been altered by the user.
*/
public function valuesChanged($form, array $values) {
foreach (self::$valuesToCheck as $field_name) {
if (!isset($form['simple_sitemap'][$field_name]['#default_value'])
|| (isset($values[$field_name]) && $values[$field_name] != $form['simple_sitemap'][$field_name]['#default_value'])) {
return TRUE;
}
}
// foreach (self::$valuesToCheck as $field_name) {
// if (!isset($form['simple_sitemap'][$field_name]['#default_value'])
// || (isset($values[$field_name]) && $values[$field_name] != $form['simple_sitemap'][$field_name]['#default_value'])) {
// return TRUE;
// }
// }
//
// return FALSE;
return FALSE;
//todo
return TRUE;
}
/**
......
......@@ -133,9 +133,9 @@
<xsl:if test="/sitemap:urlset/sitemap:url/xhtml:link">
<td>
<xsl:if test="xhtml:link">
<dl class="translation-set">
<ul class="translation-set">
<xsl:apply-templates select="xhtml:link"/>
</dl>
</ul>
</xsl:if>
</td>
</xsl:if>
......@@ -154,20 +154,17 @@
<!-- xhtml:link template -->
<xsl:template match="xhtml:link">
<xsl:variable name="url_language">
<xsl:value-of select="@hreflang"/>
</xsl:variable>
<xsl:variable name="url_location">
<xsl:value-of select="@href"/>
</xsl:variable>
<dt>
<xsl:value-of select="$url_language"/>
</dt>
<dd>
<li>
<span>
<xsl:value-of select="@hreflang"/>
</span>
<a href="{$url_location}">
<xsl:value-of select="$url_location"/>
</a>
</dd>
</li>
</xsl:template>
<!-- image:image template -->
......@@ -179,6 +176,20 @@
<a href="{$image_location}">
<xsl:value-of select="$image_location"/>
</a>
<!-- Show this element only if image:caption element is present -->
<xsl:if test="image:caption">
<div>
<span>[image-caption]</span>
<xsl:value-of select="image:caption"/>
</div>
</xsl:if>
<!-- Show this element only if image:title element is present -->
<xsl:if test="image:title">
<div>
<span>[image-title]</span>
<xsl:value-of select="image:title"/>
</div>
</xsl:if>
</li>
</xsl:template>
......
......@@ -64,29 +64,28 @@ table.sitemap thead tr .tablesorter-headerDesc .tablesorter-header-inner:after {
right: 0;
}
table.sitemap tbody tr dl.translation-set {
table.sitemap tbody tr ul {
list-style: none;
padding: 0;
margin: 0;
}
table.sitemap tbody tr dl.translation-set dt {
text-transform: uppercase;
float: left;
padding: 0;
margin: 0 5px 0 0;
table.sitemap tbody tr ul li:not(:first-of-type) {
margin-top: 5px;
}
table.sitemap tbody tr dl.translation-set dt:after {
table.sitemap tbody tr ul li span {
margin-right: 5px;
}
table.sitemap tbody tr ul li span:after {
content: ":";
}
table.sitemap tbody tr dl.translation-set dd {
padding: 0;
margin: 0;
table.sitemap tbody tr ul.translation-set li span {
text-transform: uppercase;
}
table.sitemap tbody tr ul.images {
list-style: none;
padding: 0;
margin: 0;
table.sitemap tbody tr ul.images li span {
font-style: italic;
}