Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Y
yoast_seo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
1
Merge Requests
1
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
yoast_seo
Commits
a332acf1
Commit
a332acf1
authored
Jan 30, 2018
by
chr.fritsch
Committed by
Kingdutch
Jan 30, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2730333
by chr.fritsch, Kingdutch: Content Analysis for Entities, not just nodes
parent
d63177d7
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
44 deletions
+44
-44
README.txt
README.txt
+4
-3
drush/yoast_seo.drush.inc
drush/yoast_seo.drush.inc
+13
-22
src/Form/AnalysisFormHandler.php
src/Form/AnalysisFormHandler.php
+1
-1
src/SeoManager.php
src/SeoManager.php
+14
-4
yoast_seo.info.yml
yoast_seo.info.yml
+3
-1
yoast_seo.module
yoast_seo.module
+8
-12
yoast_seo.permissions.yml
yoast_seo.permissions.yml
+1
-1
No files found.
README.txt
View file @
a332acf1
Real-time SEO for Drupal 8
----------------------
Improve your Drupal SEO: write better content using Real-time SEO for Drupal module togheter with the Yoast SEO library.
Improve your Drupal SEO: write better content using Real-time SEO for Drupal
module together with the Yoast SEO library.
https://www.drupal.org/project/yoast_seo
HOW DOES IT WORK
...
...
@@ -22,8 +23,8 @@ HOW TO CONFIGURE
----------------
By default, the Real-time SEO field is enabled for all the content types. You
can change this setting in Configuration > Development > Real-time SEO Admin Settings.
As of now, the Real-time SEO module only works on nodes and does not suppor
t
taxonomy
.
The Real-time SEO module only works on entity types that implemen
t
ContentEntityInterface (node, media and block_content) and on taxonomy term pages
.
Make sure you have the "Real-time SEO" field under "Manage form display"
Make sure you have the "Meta tags" field under "Manage form display"
...
...
drush/yoast_seo.drush.inc
View file @
a332acf1
...
...
@@ -9,14 +9,14 @@
* Implements hook_drush_command().
*/
function
yoast_seo_drush_command
()
{
$items
=
array
()
;
$items
=
[]
;
// Command yoastseo-prepare-uninstall
// prepares the module to be uninstalled.
$items
[
'yoastseo-prepare-uninstall'
]
=
array
(
$items
[
'yoastseo-prepare-uninstall'
]
=
[
'description'
=>
"Prepare uninstalling Real-time SEO. Remove fields and data."
,
'aliases'
=>
array
(
'ypu'
)
,
)
;
'aliases'
=>
[
'ypu'
]
,
]
;
return
$items
;
}
...
...
@@ -26,41 +26,32 @@ function yoast_seo_drush_command() {
*
* This enables to delete the fields from drupal so uninstalling the module
* doesn't fail.
* It does 3 things :
* - Remove Yoast SEO fields from the content view
* It does 2 things :
* - Detach Yoast SEO from all yoastseo enabled content types
* - Purge the fields list from all temporary deleted fields.
*
* @see https://www.drupal.org/node/2418659
*/
function
drush_yoast_seo_yoastseo_prepare_uninstall
()
{
$supported_entities
=
[
'node'
=>
'Node'
,
'taxonomy_term'
=>
'Taxonomy term'
,
];
$yoast_seo_manager
=
\
Drupal
::
service
(
'yoast_seo.manager'
);
/
/ 1) Remove field from content view.
$yoast_seo_manager
->
detachFieldHandlerFromContentView
(
);
/
** @var \Drupal\yoast_seo\SeoManager $yoast_seo_manager */
$yoast_seo_manager
=
\
Drupal
::
service
(
'yoast_seo.manager'
);
// 2) Detach Yoast SEO from all the content types it is attached to.
foreach
(
$supported_entities
as
$entity_type_id
=>
$entity_type_label
)
{
$enabled_bundles
=
$yoast_seo_manager
->
getEnabledBundles
(
$entity_type_id
);
if
(
!
empty
(
$enabled_bundles
))
{
foreach
(
$enabled_bundles
as
$bundle_id
)
{
echo
"detach yoast_seo fields from
$entity_type_id
$bundle_id
\n
"
;
$yoast_seo_manager
->
detachYoastSeoFields
(
$entity_type_id
,
$bundle_id
);
}
foreach
(
$yoast_seo_manager
->
getEnabledBundles
()
as
$entity_type_id
=>
$bundles
)
{
foreach
(
$bundles
as
$bundle_id
)
{
echo
"Detach Real-Time SEO fields for
{
$entity_type_id
}
{
$bundle_id
}
\n
"
;
$yoast_seo_manager
->
disableFor
(
$entity_type_id
,
$bundle_id
);
}
}
// 3) Purge field data.
do
{
field_purge_batch
(
1000
);
$properties
=
array
(
$properties
=
[
'deleted'
=>
TRUE
,
'include_deleted'
=>
TRUE
,
)
;
]
;
$fields
=
entity_load_multiple_by_properties
(
'field_config'
,
$properties
);
}
while
(
$fields
);
...
...
src/Form/AnalysisFormHandler.php
View file @
a332acf1
...
...
@@ -45,7 +45,7 @@ class AnalysisFormHandler implements EntityHandlerInterface {
}
/**
* Ajax Callback for returning
node
preview to seo library.
* Ajax Callback for returning
entity
preview to seo library.
*
* @param array $form
* The complete form array.
...
...
src/SeoManager.php
View file @
a332acf1
...
...
@@ -2,6 +2,7 @@
namespace
Drupal\yoast_seo
;
use
Drupal\Core\Entity\ContentEntityInterface
;
use
Drupal\Core\Entity\EntityTypeBundleInfoInterface
;
use
Drupal\Core\Entity\EntityTypeManagerInterface
;
use
Symfony\Component\Yaml\Yaml
;
...
...
@@ -57,10 +58,19 @@ class SeoManager {
* A list of available entity types as $id => $label.
*/
public
function
getSupportedEntityTypes
()
{
// @todo Should be the same than the ones supported by the metatag module.
return
[
'node'
=>
'Node'
,
];
$supportedEntityTypes
=
[];
foreach
(
$this
->
entityTypeManager
->
getDefinitions
()
as
$definition
)
{
if
(
$definition
->
entityClassImplements
(
ContentEntityInterface
::
class
))
{
$supportedEntityTypes
[
$definition
->
id
()]
=
$definition
->
getLabel
();
}
}
// TODO: Could be removed when d.o/project/drupal/issues/2880149 lands.
if
(
\
Drupal
::
service
(
'module_handler'
)
->
moduleExists
(
'taxonomy'
))
{
$supportedEntityTypes
[
'taxonomy_term'
]
=
'Term'
;
}
return
$supportedEntityTypes
;
}
/**
...
...
yoast_seo.info.yml
View file @
a332acf1
...
...
@@ -8,6 +8,8 @@ configure: yoast_seo.settings
dependencies
:
-
metatag
-
node
-
path
-
views
test_dependencies
:
-
node
yoast_seo.module
View file @
a332acf1
...
...
@@ -79,23 +79,15 @@ function yoast_seo_theme() {
/**
* Implements hook_entity_type_build().
*
* Sets the default yoast_seo_form form handler to
enabled
entity types.
* Sets the default yoast_seo_form form handler to
all
entity types.
*
* @see \Drupal\Core\Entity\Annotation\EntityType
*/
function
yoast_seo_entity_type_build
(
array
&
$entity_types
)
{
/* @var \Drupal\yoast_seo\SeoManager $seo_manager */
$seo_manager
=
\
Drupal
::
service
(
'yoast_seo.manager'
);
// Set the handler for all supported types.
$supported_types
=
$seo_manager
->
getSupportedEntityTypes
();
/* @var $entity_types \Drupal\Core\Entity\EntityTypeInterface[] */
foreach
(
$entity_types
as
&
$entity_type
)
{
if
(
isset
(
$supported_types
[
$entity_type
->
id
()]))
{
if
(
!
$entity_type
->
hasHandlerClass
(
'yoast_seo_preview_form'
))
{
$entity_type
->
setHandlerClass
(
'yoast_seo_preview_form'
,
AnalysisFormHandler
::
class
);
}
if
(
!
$entity_type
->
hasHandlerClass
(
'yoast_seo_preview_form'
))
{
$entity_type
->
setHandlerClass
(
'yoast_seo_preview_form'
,
AnalysisFormHandler
::
class
);
}
}
}
...
...
@@ -115,8 +107,12 @@ function yoast_seo_entity_type_build(array &$entity_types) {
* @ingroup entity_crud
*/
function
yoast_seo_entity_view_display_alter
(
EntityViewDisplayInterface
$display
,
array
$context
)
{
/* @var \Drupal\yoast_seo\SeoManager $seo_manager */
$seo_manager
=
\
Drupal
::
service
(
'yoast_seo.manager'
);
$supported_types
=
$seo_manager
->
getSupportedEntityTypes
();
// Leave Yoast field labels out of the display.
if
(
$context
[
'entity_type'
]
==
'node'
&&
$context
[
'view_mode'
]
==
'full'
)
{
if
(
!
empty
(
$supported_types
[
$context
[
'entity_type'
]])
&&
$context
[
'view_mode'
]
==
'full'
)
{
foreach
(
$display
->
getComponents
()
as
$name
=>
$options
)
{
if
(
$name
==
'field_yoast_seo'
)
{
$display
->
removeComponent
(
$name
);
...
...
yoast_seo.permissions.yml
View file @
a332acf1
...
...
@@ -5,4 +5,4 @@ administer yoast seo:
use yoast seo
:
title
:
'
Use
Real-time
SEO
for
Drupal'
description
:
'
Modify
Realtime
SEO
for
Drupal
configuration
per
individual
nod
es.'
description
:
'
Modify
Realtime
SEO
for
Drupal
configuration
per
individual
entiti
es.'
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