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
drupal
Commits
f5ec8253
Commit
f5ec8253
authored
May 10, 2013
by
Dries
Browse files
Issue
#1985138
by Berdir, Gábor Hojtsy: Fixed New autocomplete taxonomy terms not previewable.
parent
0bdc4cc7
Changes
7
Hide whitespace changes
Inline
Side-by-side
core/modules/node/lib/Drupal/node/Tests/PagePreviewTest.php
View file @
f5ec8253
...
...
@@ -68,7 +68,8 @@ function setUp() {
'parent'
=>
'0'
,
),
),
)
),
'cardinality'
=>
'-1'
,
);
field_create_field
(
$this
->
field
);
...
...
@@ -77,7 +78,7 @@ function setUp() {
'entity_type'
=>
'node'
,
'bundle'
=>
'page'
,
'widget'
=>
array
(
'type'
=>
'
options_select
'
,
'type'
=>
'
taxonomy_autocomplete
'
,
),
// Hide on full display but render on teaser.
'display'
=>
array
(
...
...
@@ -90,6 +91,9 @@ function setUp() {
),
);
field_create_instance
(
$this
->
instance
);
entity_get_display
(
'node'
,
'page'
,
'default'
)
->
setComponent
(
$this
->
field_name
)
->
save
();
}
/**
...
...
@@ -105,7 +109,7 @@ function testPagePreview() {
$edit
=
array
();
$edit
[
$title_key
]
=
$this
->
randomName
(
8
);
$edit
[
$body_key
]
=
$this
->
randomName
(
16
);
$edit
[
$term_key
]
=
$this
->
term
->
id
();
$edit
[
$term_key
]
=
$this
->
term
->
label
();
$this
->
drupalPost
(
'node/add/page'
,
$edit
,
t
(
'Preview'
));
// Check that the preview is displaying the title, body and term.
...
...
@@ -119,6 +123,49 @@ function testPagePreview() {
$this
->
assertFieldByName
(
$title_key
,
$edit
[
$title_key
],
'Title field displayed.'
);
$this
->
assertFieldByName
(
$body_key
,
$edit
[
$body_key
],
'Body field displayed.'
);
$this
->
assertFieldByName
(
$term_key
,
$edit
[
$term_key
],
'Term field displayed.'
);
// Save the node.
$this
->
drupalPost
(
'node/add/page'
,
$edit
,
t
(
'Save'
));
$node
=
$this
->
drupalGetNodeByTitle
(
$edit
[
$title_key
]);
// Check the term was displayed on the saved node.
$this
->
drupalGet
(
'node/'
.
$node
->
nid
);
$this
->
assertText
(
$edit
[
$term_key
],
'Term displayed.'
);
// Check the term appears again on the edit form.
$this
->
drupalGet
(
'node/'
.
$node
->
nid
.
'/edit'
);
$this
->
assertFieldByName
(
$term_key
,
$edit
[
$term_key
],
'Term field displayed.'
);
// Check with two new terms on the edit form, additionally to the existing
// one.
$edit
=
array
();
$newterm1
=
$this
->
randomName
(
8
);
$newterm2
=
$this
->
randomName
(
8
);
$edit
[
$term_key
]
=
$this
->
term
->
label
()
.
', '
.
$newterm1
.
', '
.
$newterm2
;
$this
->
drupalPost
(
'node/'
.
$node
->
nid
.
'/edit'
,
$edit
,
t
(
'Preview'
));
$this
->
assertRaw
(
'>'
.
$newterm1
.
'<'
,
'First new term displayed.'
);
$this
->
assertRaw
(
'>'
.
$newterm2
.
'<'
,
'Second new term displayed.'
);
// The first term should be displayed as link, the others not.
$this
->
assertLink
(
$this
->
term
->
label
());
$this
->
assertNoLink
(
$newterm1
);
$this
->
assertNoLink
(
$newterm2
);
$this
->
drupalPost
(
'node/add/page'
,
$edit
,
t
(
'Save'
));
// Check with one more new term, keeping old terms, removing the existing
// one.
$edit
=
array
();
$newterm3
=
$this
->
randomName
(
8
);
$edit
[
$term_key
]
=
$newterm1
.
', '
.
$newterm3
.
', '
.
$newterm2
;
$this
->
drupalPost
(
'node/'
.
$node
->
nid
.
'/edit'
,
$edit
,
t
(
'Preview'
));
$this
->
assertRaw
(
'>'
.
$newterm1
.
'<'
,
'First existing term displayed.'
);
$this
->
assertRaw
(
'>'
.
$newterm2
.
'<'
,
'Second existing term displayed.'
);
$this
->
assertRaw
(
'>'
.
$newterm3
.
'<'
,
'Third new term displayed.'
);
$this
->
assertNoText
(
$this
->
term
->
label
());
$this
->
assertNoLink
(
$newterm1
);
$this
->
assertNoLink
(
$newterm2
);
$this
->
assertNoLink
(
$newterm3
);
$this
->
drupalPost
(
'node/add/page'
,
$edit
,
t
(
'Save'
));
}
/**
...
...
core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/EntityReferenceTaxonomyTermRssFormatter.php
View file @
f5ec8253
...
...
@@ -38,9 +38,9 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
foreach
(
$items
as
$delta
=>
$item
)
{
$entity
->
rss_elements
[]
=
array
(
'key'
=>
'category'
,
'value'
=>
$item
[
'
target_id'
]
!=
'autocreate'
?
$item
[
'entity'
]
->
label
()
:
$item
[
'label'
]
,
'value'
=>
$item
[
'
entity'
]
->
label
()
,
'attributes'
=>
array
(
'domain'
=>
$item
[
'target_id'
]
!=
'autocreate'
?
url
(
'taxonomy/term/'
.
$item
[
'target_id'
],
array
(
'absolute'
=>
TRUE
))
:
''
,
'domain'
=>
$item
[
'target_id'
]
?
url
(
'taxonomy/term/'
.
$item
[
'target_id'
],
array
(
'absolute'
=>
TRUE
))
:
''
,
),
);
}
...
...
core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/LinkFormatter.php
View file @
f5ec8253
...
...
@@ -33,12 +33,11 @@ class LinkFormatter extends TaxonomyFormatterBase {
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
array
$items
)
{
$elements
=
array
();
// Terms whose tid is 'autocreate' do not exist yet and $item['entity'] is
// not set. Theme such terms as just their name.
// Terms without tid do not exist yet, theme such terms as just their name.
foreach
(
$items
as
$delta
=>
$item
)
{
if
(
$item
[
'tid'
]
==
'autocreate'
)
{
if
(
!
$item
[
'tid'
])
{
$elements
[
$delta
]
=
array
(
'#markup'
=>
check_plain
(
$item
[
'
name'
]
),
'#markup'
=>
check_plain
(
$item
[
'
entity'
]
->
label
()
),
);
}
else
{
...
...
core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/PlainFormatter.php
View file @
f5ec8253
...
...
@@ -33,12 +33,9 @@ class PlainFormatter extends TaxonomyFormatterBase {
public
function
viewElements
(
EntityInterface
$entity
,
$langcode
,
array
$items
)
{
$elements
=
array
();
// Terms whose tid is 'autocreate' do not exist yet and $item['entity'] is
// not set. Theme such terms as just their name.
foreach
(
$items
as
$delta
=>
$item
)
{
$name
=
(
$item
[
'tid'
]
!=
'autocreate'
?
$item
[
'entity'
]
->
label
()
:
$item
[
'name'
]);
$elements
[
$delta
]
=
array
(
'#markup'
=>
check_plain
(
$
name
),
'#markup'
=>
check_plain
(
$
item
[
'entity'
]
->
label
()
),
);
}
...
...
core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/RSSCategoryFormatter.php
View file @
f5ec8253
...
...
@@ -34,7 +34,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
// Terms whose tid is 'autocreate' do not exist yet and $item['entity'] is
// not set. Theme such terms as just their name.
foreach
(
$items
as
$item
)
{
if
(
$item
[
'tid'
]
!=
'autocreate'
)
{
if
(
$item
[
'tid'
])
{
$value
=
$item
[
'entity'
]
->
label
();
$uri
=
$item
[
'entity'
]
->
uri
();
...
...
@@ -42,7 +42,7 @@ public function viewElements(EntityInterface $entity, $langcode, array $items) {
$domain
=
url
(
$uri
[
'path'
],
$uri
[
'options'
]);
}
else
{
$value
=
$item
[
'
name'
]
;
$value
=
$item
[
'
entity'
]
->
label
()
;
$domain
=
''
;
}
$entity
->
rss_elements
[]
=
array
(
...
...
core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/formatter/TaxonomyFormatterBase.php
View file @
f5ec8253
...
...
@@ -30,7 +30,7 @@ public function prepareView(array $entities, $langcode, array &$items) {
foreach
(
$entities
as
$id
=>
$entity
)
{
foreach
(
$items
[
$id
]
as
$delta
=>
$item
)
{
// Force the array key to prevent duplicates.
if
(
$item
[
'tid'
]
!=
'autocreate'
&&
$item
[
'tid'
]
!==
FALSE
)
{
if
(
$item
[
'tid'
]
!==
FALSE
)
{
$tids
[
$item
[
'tid'
]]
=
$item
[
'tid'
];
}
}
...
...
@@ -51,7 +51,7 @@ public function prepareView(array $entities, $langcode, array &$items) {
$items
[
$id
][
$delta
][
'entity'
]
=
$terms
[
$item
[
'tid'
]];
}
// Terms to be created are not in $terms, but are still legitimate.
elseif
(
$item
[
'tid'
]
==
'autocreate'
)
{
elseif
(
$item
[
'tid'
]
==
=
FALSE
&&
isset
(
$item
[
'entity'
])
)
{
// Leave the item in place.
}
// Otherwise, unset the instance value, since the term does not exist.
...
...
core/modules/taxonomy/lib/Drupal/taxonomy/Plugin/field/widget/TaxonomyAutocompleteWidget.php
View file @
f5ec8253
...
...
@@ -86,7 +86,7 @@ public function massageFormValues(array $values, array $form, array &$form_state
// Translate term names into actual terms.
foreach
(
$values
as
$value
)
{
// See if the term exists in the chosen vocabulary and return the tid;
// otherwise, create a new
'autocreate' term for insert/upda
te.
// otherwise, create a new te
rm
.
if
(
$possibilities
=
entity_load_multiple_by_properties
(
'taxonomy_term'
,
array
(
'name'
=>
trim
(
$value
),
'vid'
=>
array_keys
(
$vocabularies
))))
{
$term
=
array_pop
(
$possibilities
);
$item
=
array
(
'tid'
=>
$term
->
id
());
...
...
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