Update to Drupal 8.2.2. For more information, see https://www.drupal.org/project/drupal/releases/8.2.2
This commit is contained in:
parent
23ffed3665
commit
507b45a0ed
378 changed files with 11434 additions and 5542 deletions
|
@ -22,6 +22,8 @@ use Drupal\Core\TypedData\ListInterface;
|
|||
*
|
||||
* When implementing this interface which extends Traversable, make sure to list
|
||||
* IteratorAggregate or Iterator before this interface in the implements clause.
|
||||
*
|
||||
* @see \Drupal\Core\Field\FieldItemInterface
|
||||
*/
|
||||
interface FieldItemListInterface extends ListInterface, AccessibleInterface {
|
||||
|
||||
|
|
|
@ -268,7 +268,26 @@ class EntityReferenceItem extends FieldItemBase implements OptionsProviderInterf
|
|||
*/
|
||||
public static function generateSampleValue(FieldDefinitionInterface $field_definition) {
|
||||
$manager = \Drupal::service('plugin.manager.entity_reference_selection');
|
||||
if ($referenceable = $manager->getSelectionHandler($field_definition)->getReferenceableEntities()) {
|
||||
|
||||
// Instead of calling $manager->getSelectionHandler($field_definition)
|
||||
// replicate the behavior to be able to override the sorting settings.
|
||||
$options = array(
|
||||
'target_type' => $field_definition->getFieldStorageDefinition()->getSetting('target_type'),
|
||||
'handler' => $field_definition->getSetting('handler'),
|
||||
'handler_settings' => $field_definition->getSetting('handler_settings') ?: array(),
|
||||
'entity' => NULL,
|
||||
);
|
||||
|
||||
$entity_type = \Drupal::entityManager()->getDefinition($options['target_type']);
|
||||
$options['handler_settings']['sort'] = [
|
||||
'field' => $entity_type->getKey('id'),
|
||||
'direction' => 'DESC',
|
||||
];
|
||||
$selection_handler = $manager->getInstance($options);
|
||||
|
||||
// Select a random number of references between the last 50 referenceable
|
||||
// entities created.
|
||||
if ($referenceable = $selection_handler->getReferenceableEntities(NULL, 'CONTAINS', 50)) {
|
||||
$group = array_rand($referenceable);
|
||||
$values['target_id'] = array_rand($referenceable[$group]);
|
||||
return $values;
|
||||
|
|
|
@ -87,11 +87,14 @@ class EntityReferenceAutocompleteWidget extends WidgetBase {
|
|||
$entity = $items->getEntity();
|
||||
$referenced_entities = $items->referencedEntities();
|
||||
|
||||
// Append the match operation to the selection settings.
|
||||
$selection_settings = $this->getFieldSetting('handler_settings') + ['match_operator' => $this->getSetting('match_operator')];
|
||||
|
||||
$element += array(
|
||||
'#type' => 'entity_autocomplete',
|
||||
'#target_type' => $this->getFieldSetting('target_type'),
|
||||
'#selection_handler' => $this->getFieldSetting('handler'),
|
||||
'#selection_settings' => $this->getFieldSetting('handler_settings'),
|
||||
'#selection_settings' => $selection_settings,
|
||||
// Entity reference field items are handling validation themselves via
|
||||
// the 'ValidReference' constraint.
|
||||
'#validate_reference' => FALSE,
|
||||
|
|
Reference in a new issue