Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
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
224
Merge Requests
224
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
drupal
Commits
7bb4e4d1
Commit
7bb4e4d1
authored
Jan 05, 2015
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2401195
by idebr, corbacho: Vocabulary restriction not working in Entity reference fields
parent
eb25fabd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
1 deletion
+85
-1
core/modules/taxonomy/src/Plugin/entity_reference/selection/TermSelection.php
...y/src/Plugin/entity_reference/selection/TermSelection.php
+2
-1
core/modules/taxonomy/src/Tests/TermEntityReferenceTest.php
core/modules/taxonomy/src/Tests/TermEntityReferenceTest.php
+83
-0
No files found.
core/modules/taxonomy/src/Plugin/entity_reference/selection/TermSelection.php
View file @
7bb4e4d1
...
...
@@ -60,7 +60,8 @@ public function getReferenceableEntities($match = NULL, $match_operator = 'CONTA
$options
=
array
();
$bundles
=
entity_get_bundles
(
'taxonomy_term'
);
$bundle_names
=
!
empty
(
$this
->
instance
[
'settings'
][
'handler_settings'
][
'target_bundles'
])
?
$this
->
instance
[
'settings'
][
'handler_settings'
][
'target_bundles'
]
:
array_keys
(
$bundles
);
$handler_settings
=
$this
->
fieldDefinition
->
getSetting
(
'handler_settings'
);
$bundle_names
=
!
empty
(
$handler_settings
[
'target_bundles'
])
?
$handler_settings
[
'target_bundles'
]
:
array_keys
(
$bundles
);
foreach
(
$bundle_names
as
$bundle
)
{
if
(
$vocabulary
=
entity_load
(
'taxonomy_vocabulary'
,
$bundle
))
{
...
...
core/modules/taxonomy/src/Tests/TermEntityReferenceTest.php
0 → 100644
View file @
7bb4e4d1
<?php
/**
* @file
* Contains \Drupal\taxonomy\Tests\TermEntityReferenceTest.
*/
namespace
Drupal\taxonomy\Tests
;
use
Drupal\field\Entity\FieldStorageConfig
;
use
Drupal\field\Entity\FieldConfig
;
/**
* Tests the settings of restricting term selection to a single vocabulary.
*
* @group taxonomy
*/
class
TermEntityReferenceTest
extends
TaxonomyTestBase
{
/**
* Modules to enable.
*
* @var array
*/
public
static
$modules
=
array
(
'entity_reference'
,
'entity_reference_test'
,
'entity_test'
);
/**
* Tests an entity reference field restricted to a single vocabulary.
*
* Creates two vocabularies with a term, then set up the entity reference
* field to limit the target vocabulary to one of them, ensuring that
* the restriction applies.
*/
function
testSelectionTestVocabularyRestriction
()
{
// Create two vocabularies.
$vocabulary
=
$this
->
createVocabulary
();
$vocabulary2
=
$this
->
createVocabulary
();
$term
=
$this
->
createTerm
(
$vocabulary
);
$term2
=
$this
->
createTerm
(
$vocabulary2
);
// Create an entity reference field.
$field_name
=
'taxonomy_'
.
$vocabulary
->
id
();
$field_storage
=
FieldStorageConfig
::
create
(
array
(
'field_name'
=>
$field_name
,
'entity_type'
=>
'entity_test'
,
'translatable'
=>
FALSE
,
'settings'
=>
array
(
'target_type'
=>
'taxonomy_term'
,
),
'type'
=>
'entity_reference'
,
'cardinality'
=>
1
,
));
$field_storage
->
save
();
$field
=
FieldConfig
::
create
(
array
(
'field_storage'
=>
$field_storage
,
'entity_type'
=>
'entity_test'
,
'bundle'
=>
'test_bundle'
,
'settings'
=>
array
(
'handler'
=>
'default'
,
'handler_settings'
=>
array
(
// Restrict selection of terms to a single vocabulary.
'target_bundles'
=>
array
(
$vocabulary
->
id
()
=>
$vocabulary
->
id
(),
),
),
),
));
$field
->
save
();
$handler
=
$this
->
container
->
get
(
'plugin.manager.entity_reference.selection'
)
->
getSelectionHandler
(
$field
);
$result
=
$handler
->
getReferenceableEntities
();
$expected_result
=
array
(
$vocabulary
->
id
()
=>
array
(
$term
->
id
()
=>
$term
->
getName
(),
),
);
$this
->
assertIdentical
(
$result
,
$expected_result
,
'Terms selection restricted to a single vocabulary.'
);
}
}
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