Commit f13b057a authored by gbyte.co's avatar gbyte.co

Merge branch '8.x-3.x' into 3014649-multiple-variaths-ui

parents 6eaf7eff e97554a1
build:
assessment:
validate_codebase:
phplint:
container_composer:
phpcs:
# phpcs will use core's specified version of Coder.
sniff-all-files: true
halt-on-fail: false
testing:
# run_tests task is executed several times in order of performance speeds.
# halt-on-fail can be set on the run_tests tasks in order to fail fast.
# suppress-deprecations is false in order to be alerted to usages of
# deprecated code.
run_tests.standard:
types: 'Simpletest,PHPUnit-Unit,PHPUnit-Kernel,PHPUnit-Functional'
testgroups: '--all'
suppress-deprecations: false
run_tests.js:
types: 'PHPUnit-FunctionalJavascript'
testgroups: '--all'
suppress-deprecations: false
nightwatchjs: { }
......@@ -23,7 +23,7 @@ function hook_simple_sitemap_links_alter(array &$links, $sitemap_variant) {
// Remove German URL for a certain path in the hreflang sitemap.
foreach ($links as $key => $link) {
if ($link['path'] === 'node/1') {
if ($link['meta']['path'] === 'node/1') {
// Remove 'loc' URL if it points to a german site.
if ($link['langcode'] === 'de') {
......
......@@ -92,7 +92,6 @@ function simple_sitemap_schema() {
'id' => [
'description' => 'Sitemap chunk unique identifier.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'unsigned' => TRUE,
],
......@@ -106,7 +105,6 @@ function simple_sitemap_schema() {
'delta' => [
'description' => 'Delta of the chunk within the type scope.',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'unsigned' => TRUE,
],
......@@ -169,6 +167,7 @@ function simple_sitemap_schema() {
],
'primary key' => ['id'],
];
return $schema;
}
......@@ -676,3 +675,32 @@ function simple_sitemap_update_8217() {
return t('The XML sitemaps need to be regenerated.');
}
/**
* Changing id and delta fields of simple_sitemap table from smallint to int.
*/
function simple_sitemap_update_8301() {
$schema = \Drupal::database()->schema();
$schema->changeField(
'simple_sitemap',
'id',
'id', [
'description' => 'Sitemap chunk unique identifier.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
]
);
$schema->changeField(
'simple_sitemap',
'delta',
'delta', [
'description' => 'Delta of the chunk within the variant scope.',
'type' => 'int',
'not null' => TRUE,
'unsigned' => TRUE,
]
);
}
......@@ -171,30 +171,4 @@ class EntityHelper {
return $entity_query->execute();
}
/**
* Gets a list of image URLs for specified entity ID.
*
* @param string $entity_type_name
* The name of the entity type in which the images are used.
* @param string $entity_id
* The ID of the entity.
*
* @return array
* An array containing the URLs of the images.
*/
public function getEntityImageUrls($entity_type_name, $entity_id) {
$query = $this->db->select('file_managed', 'fm');
$query->fields('fm', ['uri']);
$query->join('file_usage', 'fu', 'fu.fid = fm.fid');
$query->condition('fm.filemime', 'image/%', 'LIKE');
$query->condition('fu.type', $entity_type_name);
$query->condition('fu.id', $entity_id);
foreach ($query->execute() as $row) {
$imageUris[] = file_create_url($row->uri);
}
return !empty($imageUris) ? $imageUris : [];
}
}
......@@ -162,6 +162,12 @@ class DefaultSitemapGenerator extends SitemapGeneratorBase {
foreach ($link['images'] as $image) {
$this->writer->startElement('image:image');
$this->writer->writeElement('image:loc', $image['path']);
if (strlen($image['title']) > 0) {
$this->writer->writeElement('image:title', $image['title']);
}
if (strlen($image['alt']) > 0) {
$this->writer->writeElement('image:caption', $image['alt']);
}
$this->writer->endElement();
}
}
......
......@@ -166,7 +166,7 @@ abstract class SitemapGeneratorBase extends SimplesitemapPluginBase implements S
$this->writer->startElement('sitemap');
$this->writer->writeElement('loc', $this->getCustomBaseUrl()
. '/' . (!$this->isDefaultVariant() ? ($chunk_data->type . '/') : '') . 'sitemap.xml?page=' . $chunk_data->delta);
$this->writer->writeElement('lastmod', date_iso8601($chunk_data->sitemap_created));
$this->writer->writeElement('lastmod', date('c', $chunk_data->sitemap_created));
$this->writer->endElement();
}
......
......@@ -119,11 +119,11 @@ class CustomUrlGenerator extends EntityUrlGeneratorBase {
$path_data = [
'url' => $url_object,
'lastmod' => method_exists($entity, 'getChangedTime')
? date_iso8601($entity->getChangedTime()) : NULL,
? date('c', $entity->getChangedTime()) : NULL,
'priority' => isset($data_set['priority']) ? $data_set['priority'] : NULL,
'changefreq' => !empty($data_set['changefreq']) ? $data_set['changefreq'] : NULL,
'images' => $this->includeImages && method_exists($entity, 'getEntityTypeId')
? $this->getImages($entity->getEntityTypeId(), $entity->id())
'images' => $this->includeImages && !empty($entity)
? $this->getEntityImageData($entity)
: [],
'meta' => [
'path' => $path,
......
......@@ -153,10 +153,16 @@ class EntityMenuLinkContentUrlGenerator extends EntityUrlGeneratorBase {
}
}
// There can be internal paths that are not rooted, like 'base:/path'.
if ($url_object->isRouted()) {
// Do not include paths that have no URL.
if($url_object->getRouteName() === '<nolink>') {
return FALSE;
}
$path = $url_object->getInternalPath();
}
// There can be internal paths that are not rooted, like 'base:/path'.
else { // Handle base scheme.
if (strpos($uri = $url_object->toUriString(), 'base:/') === 0 ) {
$path = $uri[6] === '/' ? substr($uri, 7) : substr($uri, 6);
......@@ -173,12 +179,12 @@ class EntityMenuLinkContentUrlGenerator extends EntityUrlGeneratorBase {
$path_data = [
'url' => $url_object,
'lastmod' => !empty($entity) && method_exists($entity, 'getChangedTime')
? date_iso8601($entity->getChangedTime())
? date('c', $entity->getChangedTime())
: NULL,
'priority' => isset($entity_settings['priority']) ? $entity_settings['priority'] : NULL,
'changefreq' => !empty($entity_settings['changefreq']) ? $entity_settings['changefreq'] : NULL,
'images' => !empty($entity_settings['include_images']) && !empty($entity)
? $this->getImages($entity->getEntityTypeId(), $entity->id())
? $this->getEntityImageData($entity)
: [],
// Additional info useful in hooks.
......
......@@ -161,11 +161,11 @@ class EntityUrlGenerator extends EntityUrlGeneratorBase {
return [
'url' => $url_object,
'lastmod' => method_exists($entity, 'getChangedTime') ? date_iso8601($entity->getChangedTime()) : NULL,
'lastmod' => method_exists($entity, 'getChangedTime') ? date('c', $entity->getChangedTime()) : NULL,
'priority' => isset($entity_settings['priority']) ? $entity_settings['priority'] : NULL,
'changefreq' => !empty($entity_settings['changefreq']) ? $entity_settings['changefreq'] : NULL,
'images' => !empty($entity_settings['include_images'])
? $this->getImages($entity_type_name, $entity_id)
? $this->getEntityImageData($entity)
: [],
// Additional info useful in hooks.
......
......@@ -5,6 +5,7 @@ namespace Drupal\simple_sitemap\Plugin\simple_sitemap\UrlGenerator;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\Core\Url;
use Drupal\file\Entity\File;
use Drupal\simple_sitemap\EntityHelper;
use Drupal\simple_sitemap\Logger;
use Drupal\simple_sitemap\Simplesitemap;
......@@ -204,15 +205,24 @@ abstract class EntityUrlGeneratorBase extends UrlGeneratorBase {
}
/**
* @param string $entity_type_name
* @param string $entity_id
* @param \Drupal\Core\Entity\ContentEntityBase $entity
*
* @return array
*/
protected function getImages($entity_type_name, $entity_id) {
$images = [];
foreach ($this->entityHelper->getEntityImageUrls($entity_type_name, $entity_id) as $url) {
$images[]['path'] = $this->replaceBaseUrlWithCustom($url);
protected function getEntityImageData(ContentEntityBase $entity) {
$image_data = [];
foreach ($entity->getFieldDefinitions() as $field) {
if ($field->getType() === 'image') {
foreach ($entity->get($field->getName())->getValue() as $value) {
$image_data[] = [
'path' => file_create_url(File::load($value['target_id'])->getFileUri()),
'alt' => $value['alt'],
'title' => $value['title'],
] ;
}
}
}
return $images;
return $image_data;
}
}
......@@ -718,6 +718,7 @@ class Simplesitemap {
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
*
* @todo multiple variants
* @todo: May want to use Simplesitemap::supplementDefaultSettings('entity', $settings) inside here instead of calling it everywhere this method is called.
*/
public function getEntityInstanceSettings($entity_type_id, $id) {
if (empty($variants = $this->getVariants(FALSE))) {
......
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