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
21ce2aa7
Commit
21ce2aa7
authored
17 years ago
by
Gábor Hojtsy
Browse files
Options
Downloads
Patches
Plain Diff
#163728
by yasheshb and Desbeers: taxonomy data was lost on node preview
parent
0afce23c
No related branches found
No related tags found
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
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/taxonomy/taxonomy.module
+71
-12
71 additions, 12 deletions
modules/taxonomy/taxonomy.module
with
71 additions
and
12 deletions
modules/taxonomy/taxonomy.module
+
71
−
12
View file @
21ce2aa7
...
...
@@ -42,17 +42,32 @@ function taxonomy_theme() {
function
taxonomy_link
(
$type
,
$node
=
NULL
)
{
if
(
$type
==
'taxonomy terms'
&&
$node
!=
NULL
)
{
$links
=
array
();
// If previewing, the terms must be converted to objects first.
if
(
$node
->
build_mode
==
NODE_BUILD_PREVIEW
)
{
$node
->
taxonomy
=
taxonomy_preview_terms
(
$node
);
}
if
(
!
empty
(
$node
->
taxonomy
))
{
foreach
(
$node
->
taxonomy
as
$term
)
{
// On preview, we get tids.
if
(
is_numeric
(
$term
))
{
$term
=
taxonomy_get_term
(
$term
);
// During preview the free tagging terms are in an array unlike the other terms which are objects.
// So we have to check if a $term is an object or not.
if
(
is_object
(
$term
))
{
$links
[
'taxonomy_term_'
.
$term
->
tid
]
=
array
(
'title'
=>
$term
->
name
,
'href'
=>
taxonomy_term_path
(
$term
),
'attributes'
=>
array
(
'rel'
=>
'tag'
,
'title'
=>
strip_tags
(
$term
->
description
))
);
}
// Previewing free tagging terms; we don't link them because the term-page might not exist yet.
else
{
foreach
(
$term
as
$free_typed
)
{
$typed_terms
=
drupal_explode_tags
(
$free_typed
);
foreach
(
$typed_terms
as
$typed_term
)
{
$links
[
'taxonomy_preview_term_'
.
$typed_term
]
=
array
(
'title'
=>
$typed_term
,
);
}
}
}
$links
[
'taxonomy_term_'
.
$term
->
tid
]
=
array
(
'title'
=>
$term
->
name
,
'href'
=>
taxonomy_term_path
(
$term
),
'attributes'
=>
array
(
'rel'
=>
'tag'
,
'title'
=>
strip_tags
(
$term
->
description
))
);
}
}
...
...
@@ -419,6 +434,10 @@ function taxonomy_form_alter(&$form, $form_state, $form_id) {
$terms
=
empty
(
$node
->
nid
)
?
array
()
:
taxonomy_node_get_terms
(
$node
);
}
else
{
// After preview the terms must be converted to objects.
if
(
isset
(
$form_state
[
'node_preview'
]))
{
$node
->
taxonomy
=
taxonomy_preview_terms
(
$node
);
}
$terms
=
$node
->
taxonomy
;
}
...
...
@@ -426,8 +445,13 @@ function taxonomy_form_alter(&$form, $form_state, $form_id) {
while
(
$vocabulary
=
db_fetch_object
(
$c
))
{
if
(
$vocabulary
->
tags
)
{
$typed_string
=
taxonomy_implode_tags
(
$terms
,
$vocabulary
->
vid
)
.
(
array_key_exists
(
'tags'
,
$terms
)
?
$terms
[
'tags'
][
$vocabulary
->
vid
]
:
NULL
);
if
(
isset
(
$form_state
[
'node_preview'
]))
{
// Typed string can be changed by the user before preview, so we just insert the tags directly as provided in the form.
$typed_string
=
$node
->
taxonomy
[
'tags'
][
$vocabulary
->
vid
];
}
else
{
$typed_string
=
taxonomy_implode_tags
(
$terms
,
$vocabulary
->
vid
)
.
(
array_key_exists
(
'tags'
,
$terms
)
?
$terms
[
'tags'
][
$vocabulary
->
vid
]
:
NULL
);
}
if
(
$vocabulary
->
help
)
{
$help
=
$vocabulary
->
help
;
}
...
...
@@ -447,8 +471,9 @@ function taxonomy_form_alter(&$form, $form_state, $form_id) {
else
{
// Extract terms belonging to the vocabulary in question.
$default_terms
=
array
();
foreach
(
$terms
as
$term
)
{
if
(
$term
->
vid
==
$vocabulary
->
vid
)
{
foreach
(
$terms
as
$term
)
{
// Free tagging has no default terms and also no vid after preview.
if
(
isset
(
$term
->
vid
)
&&
$term
->
vid
==
$vocabulary
->
vid
)
{
$default_terms
[
$term
->
tid
]
=
$term
;
}
}
...
...
@@ -468,8 +493,42 @@ function taxonomy_form_alter(&$form, $form_state, $form_id) {
}
$form
[
'taxonomy'
][
'#weight'
]
=
-
3
;
$form
[
'taxonomy'
][
'#tree'
]
=
TRUE
;
}
}
}
/**
* Helper function to covert terms after a preview.
*
* After preview the tags are an array instead of proper objects. This function
* converts them back to objects with the exception of 'free tagging' terms,
* because new tags can be added by the user before preview and those do not
* yet exist in the database. We therefore save those tags as a string so
* we can fill the form again after the preview.
*/
function
taxonomy_preview_terms
(
$node
)
{
$taxonomy
=
array
();
foreach
(
$node
->
taxonomy
as
$key
=>
$term
)
{
unset
(
$node
->
taxonomy
[
$key
]);
// A 'Multiple select' and a 'Free tagging' field returns an array.
if
(
is_array
(
$term
))
{
foreach
(
$term
as
$tid
)
{
if
(
$key
==
'tags'
)
{
// Free tagging; the values will be saved for later as strings
// instead of objects to fill the form again.
$taxonomy
[
'tags'
]
=
$term
;
}
else
{
$taxonomy
[
$tid
]
=
taxonomy_get_term
(
$tid
);
}
}
}
// A 'Single select' field returns the term id.
elseif
(
$term
)
{
$taxonomy
[
$term
]
=
taxonomy_get_term
(
$term
);
}
}
return
$taxonomy
;
}
/**
...
...
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