Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
taxonomy_set_lineage
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
taxonomy_set_lineage
Commits
2ff8ddb2
Commit
2ff8ddb2
authored
3 years ago
by
Alex Goh
Committed by
Andreas Koepke
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#2356131
by alexgkt, akoepke: Support for entityreference module
parent
abd685be
Branches
7.x-1.x
Tags
7.x-1.1
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
taxonomy_set_lineage.admin.inc
+8
-0
8 additions, 0 deletions
taxonomy_set_lineage.admin.inc
taxonomy_set_lineage.module
+17
-5
17 additions, 5 deletions
taxonomy_set_lineage.module
with
25 additions
and
5 deletions
taxonomy_set_lineage.admin.inc
+
8
−
0
View file @
2ff8ddb2
...
...
@@ -56,6 +56,14 @@ function taxonomy_set_lineage_config_form(array $form, array &$form_state) {
}
$taxonomy_fields
=
field_read_fields
(
array
(
'type'
=>
'taxonomy_term_reference'
));
$entity_reference_fields
=
field_read_fields
(
array
(
'type'
=>
'entityreference'
));
foreach
(
$entity_reference_fields
as
$field_name
=>
$info
)
{
if
(
$info
[
'settings'
][
'target_type'
]
===
'taxonomy_term'
)
{
$taxonomy_fields
[
$field_name
]
=
$info
;
}
}
foreach
(
$taxonomy_fields
as
$field_name
=>
$info
)
{
$base_info
=
field_info_field
(
$field_name
);
...
...
This diff is collapsed.
Click to expand it.
taxonomy_set_lineage.module
+
17
−
5
View file @
2ff8ddb2
...
...
@@ -109,6 +109,16 @@ function _taxonomy_set_lineage_vocab_to_instance_field_name($entity, $entity_typ
return
$field
[
'field_name'
];
}
}
if
(
$field
[
'type'
]
===
'entityreference'
)
{
if
(
$field
[
'settings'
][
'target_type'
]
===
'taxonomy_term'
)
{
$bundles
=
array_keys
(
$field
[
'settings'
][
'handler_settings'
][
'target_bundles'
]);
$found_vocab_machine_name
=
$bundles
[
0
];
// If the vocab we are looking for is found in field, return field name.
if
(
$found_vocab_machine_name
===
$taxonomy_machine_name
)
{
return
$field
[
'field_name'
];
}
}
}
}
}
...
...
@@ -136,12 +146,13 @@ function _taxonomy_set_lineage_field_values_updated($entity, $tax_field_name) {
// Is there something to do?
if
(
isset
(
$entity
->
{
$tax_field_name
})
&&
is_array
(
$entity
->
{
$tax_field_name
}))
{
foreach
(
$entity
->
{
$tax_field_name
}
as
$lang_code
=>
$values
)
{
$key
=
isset
(
$values
[
0
][
'target_id'
])
?
'target_id'
:
'tid'
;
// Two loops to check for changes. First the new state.
$tids
=
array_column
(
$values
,
'tid'
);
$tids
=
array_column
(
$values
,
$key
);
// Now the old version of the entity.
$original_tids
=
array
();
if
(
isset
(
$entity
->
original
->
{
$tax_field_name
}[
$lang_code
]))
{
$original_tids
=
array_column
(
$entity
->
original
->
{
$tax_field_name
}[
$lang_code
],
'tid'
);
$original_tids
=
array_column
(
$entity
->
original
->
{
$tax_field_name
}[
$lang_code
],
$key
);
}
// Are there changes?
asort
(
$tids
);
...
...
@@ -178,19 +189,20 @@ function _taxonomy_set_lineage_field_values_updated($entity, $tax_field_name) {
function
_taxonomy_set_lineage_process_field
(
$entity
,
$tax_field_name
)
{
if
(
isset
(
$entity
->
{
$tax_field_name
})
&&
is_array
(
$entity
->
{
$tax_field_name
}))
{
foreach
(
$entity
->
{
$tax_field_name
}
as
$lang_code
=>
$values
)
{
$tids
=
array_column
(
$values
,
'tid'
);
$key
=
isset
(
$values
[
0
][
'target_id'
])
?
'target_id'
:
'tid'
;
$tids
=
array_column
(
$values
,
$key
);
$new_tids
=
$tids
;
foreach
(
$new_tids
as
$tid
)
{
// Get full ancestry of term which includes child term.
$parent_term_objects
=
taxonomy_get_parents_all
(
$tid
);
if
(
count
(
$parent_term_objects
)
>
1
)
{
// Find delta of child TID.
$delta
=
array_search
(
$tid
,
array_column
(
$values
,
'tid'
));
$delta
=
array_search
(
$tid
,
array_column
(
$values
,
$key
));
$new_values
=
[];
// Reverse parents so we can add them in the correct order.
foreach
(
array_reverse
(
$parent_term_objects
,
TRUE
)
as
$parent
)
{
if
(
!
in_array
(
$parent
->
tid
,
$tids
))
{
$new_values
[]
=
[
'tid'
=>
$parent
->
tid
];
$new_values
[]
=
[
$key
=>
$parent
->
tid
];
}
}
array_splice
(
$values
,
$delta
,
0
,
$new_values
);
...
...
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