Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Commits
40681d96
Commit
40681d96
authored
11 years ago
by
catch
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#1980822
by Berdir, sun, vladan.me, twistor: Support any entity with path.module.
parent
8b40554c
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!7452
Issue #1797438. HTML5 validation is preventing form submit and not fully...
,
!789
Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/modules/path/lib/Drupal/path/Plugin/Field/FieldType/PathItem.php
+52
-1
52 additions, 1 deletion
.../path/lib/Drupal/path/Plugin/Field/FieldType/PathItem.php
core/modules/path/path.module
+0
-47
0 additions, 47 deletions
core/modules/path/path.module
with
52 additions
and
48 deletions
core/modules/path/lib/Drupal/path/Plugin/Field/FieldType/PathItem.php
+
52
−
1
View file @
40681d96
...
...
@@ -33,7 +33,7 @@ class PathItem extends FieldItemBase {
static
$propertyDefinitions
;
/**
*
Implements \Drupal\Core\TypedData\ComplexDataInterface::getPropertyDefinitions().
*
{@inheritdoc}
*/
public
function
getPropertyDefinitions
()
{
if
(
!
isset
(
static
::
$propertyDefinitions
))
{
...
...
@@ -53,4 +53,55 @@ public static function schema(FieldDefinitionInterface $field_definition) {
return
array
();
}
/**
* {@inheritdoc}
*/
public
function
preSave
()
{
$this
->
alias
=
trim
(
$this
->
alias
);
}
/**
* {@inheritdoc}
*/
public
function
insert
()
{
if
(
$this
->
alias
)
{
$entity
=
$this
->
getEntity
();
// Ensure fields for programmatic executions.
$langcode
=
$entity
->
language
()
->
id
;
if
(
$path
=
\Drupal
::
service
(
'path.crud'
)
->
save
(
$entity
->
getSystemPath
(),
$this
->
alias
,
$langcode
))
{
$this
->
pid
=
$path
[
'pid'
];
}
}
}
/**
* {@inheritdoc}
*/
public
function
update
()
{
// Delete old alias if user erased it.
if
(
$this
->
pid
&&
!
$this
->
alias
)
{
\Drupal
::
service
(
'path.crud'
)
->
delete
(
array
(
'pid'
=>
$this
->
pid
));
}
// Only save a non-empty alias.
elseif
(
$this
->
alias
)
{
$entity
=
$this
->
getEntity
();
// Ensure fields for programmatic executions.
$langcode
=
$entity
->
language
()
->
id
;
\Drupal
::
service
(
'path.crud'
)
->
save
(
$entity
->
getSystemPath
(),
$this
->
alias
,
$langcode
,
$this
->
pid
);
}
}
/**
* {@inheritdoc}
*/
public
function
delete
()
{
// Delete all aliases associated with this entity.
$entity
=
$this
->
getEntity
();
\Drupal
::
service
(
'path.crud'
)
->
delete
(
array
(
'source'
=>
$entity
->
getSystemPath
()));
}
}
This diff is collapsed.
Click to expand it.
core/modules/path/path.module
+
0
−
47
View file @
40681d96
...
...
@@ -231,53 +231,6 @@ function path_entity_field_info($entity_type) {
}
}
/**
* Implements hook_entity_insert().
*
* @todo: Move this to methods on the FieldItem class.
*/
function
path_entity_insert
(
EntityInterface
$entity
)
{
if
(
$entity
instanceof
ContentEntityInterface
&&
$entity
->
hasField
(
'path'
))
{
$entity
->
path
->
alias
=
trim
(
$entity
->
path
->
alias
);
// Only save a non-empty alias.
if
(
!
empty
(
$entity
->
path
->
alias
))
{
// Ensure fields for programmatic executions.
$langcode
=
$entity
->
language
()
->
id
;
\Drupal
::
service
(
'path.crud'
)
->
save
(
$entity
->
getSystemPath
(),
$entity
->
path
->
alias
,
$langcode
);
}
}
}
/**
* Implements hook_entity_update().
*/
function
path_entity_update
(
EntityInterface
$entity
)
{
if
(
$entity
instanceof
ContentEntityInterface
&&
$entity
->
hasField
(
'path'
))
{
$entity
->
path
->
alias
=
trim
(
$entity
->
path
->
alias
);
// Delete old alias if user erased it.
if
(
$entity
->
path
->
pid
&&
!
$entity
->
path
->
alias
)
{
\Drupal
::
service
(
'path.crud'
)
->
delete
(
array
(
'pid'
=>
$entity
->
path
->
pid
));
}
// Only save a non-empty alias.
if
(
$entity
->
path
->
alias
)
{
$pid
=
$entity
->
path
->
pid
;
// Ensure fields for programmatic executions.
$langcode
=
$entity
->
language
()
->
id
;
\Drupal
::
service
(
'path.crud'
)
->
save
(
$entity
->
getSystemPath
(),
$entity
->
path
->
alias
,
$langcode
,
$pid
);
}
}
}
/**
* Implements hook_entity_predelete().
*/
function
path_entity_predelete
(
EntityInterface
$entity
)
{
if
(
$entity
instanceof
ContentEntityInterface
&&
$entity
->
hasField
(
'path'
))
{
// Delete all aliases associated with this term.
\Drupal
::
service
(
'path.crud'
)
->
delete
(
array
(
'source'
=>
$entity
->
getSystemPath
()));
}
}
/**
* Implements hook_library_info().
*/
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment