Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
project
simple_sitemap
Commits
e63c8e6c
Commit
e63c8e6c
authored
Sep 25, 2017
by
Pawel G
Browse files
Clean up
parent
a26700d7
Changes
7
Hide whitespace changes
Inline
Side-by-side
simple_sitemap.api.php
View file @
e63c8e6c
...
...
@@ -50,7 +50,9 @@ function hook_simple_sitemap_arbitrary_links_alter(&$arbitrary_links) {
'priority'
=>
'0.5'
,
'lastmod'
=>
'2012-10-12T17:40:30+02:00'
,
'changefreq'
=>
'weekly'
,
'images'
=>
[
'http://path-to-image.png'
]
'images'
=>
[
[
'path'
=>
'http://path-to-image.png'
]
]
];
}
...
...
src/Batch/ArbitraryUrlGenerator.php
View file @
e63c8e6c
...
...
@@ -12,12 +12,14 @@ class ArbitraryUrlGenerator extends UrlGeneratorBase implements UrlGeneratorInte
* Batch function that adds arbitrary URLs to the sitemap.
*
* @param mixed $arbitrary_paths
*
* @see \hook_simple_sitemap_arbitrary_links_alter()
*/
public
function
generate
(
$arbitrary_paths
)
{
foreach
(
$this
->
getBatchIterationElements
(
$arbitrary_paths
)
as
$i
=>
$path_data
)
{
$this
->
setCurrentId
(
$i
);
$this
->
context
[
'results'
][
'generate'
][]
=
$path_data
;
$this
->
addUrl
(
$path_data
)
;
}
$this
->
processSegment
();
}
...
...
src/Batch/CustomUrlGenerator.php
View file @
e63c8e6c
...
...
@@ -54,7 +54,7 @@ class CustomUrlGenerator extends UrlGeneratorBase implements UrlGeneratorInterfa
'id'
=>
$entity
->
id
()
];
}
$this
->
addUrl
Variants
(
$url_object
,
$path_data
,
$
entity
);
$this
->
addUrl
(
$path_data
,
$
url_object
);
}
$this
->
processSegment
();
}
...
...
src/Batch/EntityUrlGenerator.php
View file @
e63c8e6c
...
...
@@ -64,15 +64,28 @@ class EntityUrlGenerator extends UrlGeneratorBase implements UrlGeneratorInterfa
'priority'
=>
isset
(
$entity_settings
[
'priority'
])
?
$entity_settings
[
'priority'
]
:
NULL
,
'changefreq'
=>
!
empty
(
$entity_settings
[
'changefreq'
])
?
$entity_settings
[
'changefreq'
]
:
NULL
,
'images'
=>
$entity_settings
[
'include_images'
]
?
$this
->
entityHelper
->
getEntity
Image
Uri
s
(
$entity_info
[
'entity_type_name'
],
$entity_id
)
?
$this
->
get
Images
(
$entity_info
[
'entity_type_name'
],
$entity_id
)
:
[]
];
$this
->
addUrl
Variants
(
$url_object
,
$path_data
,
$
entity
);
$this
->
addUrl
(
$path_data
,
$
url_object
);
}
$this
->
processSegment
();
}
/**
* @param $entity_type_name
* @param $entity_id
* @return array
*/
protected
function
getImages
(
$entity_type_name
,
$entity_id
)
{
$images
=
[];
foreach
(
$this
->
entityHelper
->
getEntityImageUrls
(
$entity_type_name
,
$entity_id
)
as
$Url
)
{
$images
[][
'path'
]
=
$Url
;
}
return
$images
;
}
/**
* @param array $entity_info
* @return \Drupal\Core\Entity\EntityInterface[]
...
...
src/Batch/UrlGeneratorBase.php
View file @
e63c8e6c
...
...
@@ -158,14 +158,26 @@ class UrlGeneratorBase {
return
FALSE
;
}
/**
* @param array $path_data
* @param \Drupal\Core\Url|NULL $url_object
*/
protected
function
addUrl
(
array
$path_data
,
Url
$url_object
=
NULL
)
{
if
(
$url_object
!==
NULL
)
{
$this
->
addUrlVariants
(
$path_data
,
$url_object
);
}
else
{
$this
->
context
[
'results'
][
'generate'
][]
=
$path_data
;
}
}
/**
* @param Url $url_object
* @param array $path_data
* @param Entity $entity
*/
protected
function
addUrlVariants
(
Url
$url_object
,
array
$path_data
,
Entity
$entity
=
null
)
{
protected
function
addUrlVariants
(
array
$path_data
,
Url
$url_object
)
{
$alternate_urls
=
[];
$entity
=
$this
->
entityHelper
->
getEntityFromUrlObject
(
$url_object
);
$translation_languages
=
$entity
instanceof
ContentEntityBase
&&
$this
->
batchInfo
[
'skip_untranslated'
]
?
$entity
->
getTranslationLanguages
()
:
$this
->
languages
;
...
...
@@ -199,7 +211,8 @@ class UrlGeneratorBase {
}
foreach
(
$alternate_urls
as
$langcode
=>
$url
)
{
$this
->
context
[
'results'
][
'generate'
][]
=
$path_data
+
[
'langcode'
=>
$langcode
,
'url'
=>
$url
,
'alternate_urls'
=>
$alternate_urls
];
$this
->
context
[
'results'
][
'generate'
][]
=
$path_data
+
[
'langcode'
=>
$langcode
,
'url'
=>
$url
,
'alternate_urls'
=>
$alternate_urls
];
}
}
...
...
src/EntityHelper.php
View file @
e63c8e6c
...
...
@@ -118,7 +118,7 @@ class EntityHelper {
* @param $entity_id
* @return array
*/
public
function
getEntityImageUr
i
s
(
$entity_type_name
,
$entity_id
)
{
public
function
getEntityImageUr
l
s
(
$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'
);
...
...
src/SitemapGenerator.php
View file @
e63c8e6c
...
...
@@ -37,7 +37,6 @@ class SitemapGenerator {
*/
protected
$db
;
/**
* @var \Drupal\Core\Language\LanguageManagerInterface
*/
...
...
@@ -63,12 +62,18 @@ class SitemapGenerator {
*/
protected
$generator
;
/**
* @var array
*/
protected
static
$attributes
=
[
'xmlns'
=>
self
::
XMLNS
,
'xmlns:xhtml'
=>
self
::
XMLNS_XHTML
,
'xmlns:image'
=>
self
::
XMLNS_IMAGE
,
];
/**
* @var array
*/
protected
static
$indexAttributes
=
[
'xmlns'
=>
self
::
XMLNS
,
];
...
...
@@ -336,9 +341,9 @@ class SitemapGenerator {
// Add images if any.
if
(
!
empty
(
$link
[
'images'
]))
{
foreach
(
$link
[
'images'
]
as
$image
_url
)
{
foreach
(
$link
[
'images'
]
as
$image
)
{
$writer
->
startElement
(
'image:image'
);
$writer
->
writeElement
(
'image:loc'
,
$image
_url
);
$writer
->
writeElement
(
'image:loc'
,
$image
[
'path'
]
);
$writer
->
endElement
();
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment