Update to Drupal 8.0.0 beta 14. For more information, see https://drupal.org/node/2544542
This commit is contained in:
parent
3b2511d96d
commit
81ccda77eb
2155 changed files with 54307 additions and 46870 deletions
|
@ -7,7 +7,6 @@
|
|||
|
||||
namespace Drupal\Core\Field\Entity;
|
||||
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Field\BaseFieldDefinition;
|
||||
use Drupal\Core\Field\FieldConfigBase;
|
||||
|
@ -103,10 +102,10 @@ class BaseFieldOverride extends FieldConfigBase {
|
|||
throw new FieldException('Attempt to create a base field bundle override of a field without a field_name');
|
||||
}
|
||||
if (empty($values['entity_type'])) {
|
||||
throw new FieldException(SafeMarkup::format('Attempt to create a base field bundle override of field @field_name without an entity_type', array('@field_name' => $values['field_name'])));
|
||||
throw new FieldException("Attempt to create a base field bundle override of field {$values['field_name']} without an entity_type");
|
||||
}
|
||||
if (empty($values['bundle'])) {
|
||||
throw new FieldException(SafeMarkup::format('Attempt to create a base field bundle override of field @field_name without a bundle', array('@field_name' => $values['field_name'])));
|
||||
throw new FieldException("Attempt to create a base field bundle override of field {$values['field_name']} without a bundle");
|
||||
}
|
||||
|
||||
parent::__construct($values, $entity_type);
|
||||
|
@ -188,10 +187,10 @@ class BaseFieldOverride extends FieldConfigBase {
|
|||
else {
|
||||
// Some updates are always disallowed.
|
||||
if ($this->entity_type != $this->original->entity_type) {
|
||||
throw new FieldException(SafeMarkup::format('Cannot change the entity_type of an existing base field bundle override (entity type:@entity_type, bundle:@bundle, field name: @field_name)', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type, '@bundle' => $this->original->bundle)));
|
||||
throw new FieldException("Cannot change the entity_type of an existing base field bundle override (entity type:{$this->entity_type}, bundle:{$this->original->bundle}, field name: {$this->field_name})");
|
||||
}
|
||||
if ($this->bundle != $this->original->bundle && empty($this->bundleRenameAllowed)) {
|
||||
throw new FieldException(SafeMarkup::format('Cannot change the bundle of an existing base field bundle override (entity type:@entity_type, bundle:@bundle, field name: @field_name)', array('@field_name' => $this->field_name, '@entity_type' => $this->entity_type, '@bundle' => $this->original->bundle)));
|
||||
throw new FieldException("Cannot change the bundle of an existing base field bundle override (entity type:{$this->entity_type}, bundle:{$this->original->bundle}, field name: {$this->field_name})");
|
||||
}
|
||||
$previous_definition = $this->original;
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ use Drupal\Core\Config\Entity\ConfigEntityBase;
|
|||
use Drupal\Core\Entity\EntityStorageInterface;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Field\TypedData\FieldItemDataDefinition;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
|
||||
/**
|
||||
* Base class for configurable field definitions.
|
||||
|
@ -254,7 +253,7 @@ abstract class FieldConfigBase extends ConfigEntityBase implements FieldConfigIn
|
|||
$bundle_entity_type_id = $this->entityManager()->getDefinition($this->entity_type)->getBundleEntityType();
|
||||
if ($bundle_entity_type_id != 'bundle') {
|
||||
if (!$bundle_entity = $this->entityManager()->getStorage($bundle_entity_type_id)->load($this->bundle)) {
|
||||
throw new \LogicException(SafeMarkup::format('Missing bundle entity, entity type %type, entity id %bundle.', array('%type' => $bundle_entity_type_id, '%bundle' => $this->bundle)));
|
||||
throw new \LogicException("Missing bundle entity, entity type {$bundle_entity_type_id}, entity id {$this->bundle}.");
|
||||
}
|
||||
$this->addDependency('config', $bundle_entity->getConfigDependencyName());
|
||||
}
|
||||
|
|
|
@ -201,12 +201,7 @@ abstract class FieldItemBase extends Map implements FieldItemInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function insert() { }
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update() { }
|
||||
public function postSave($update) { }
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
|
|
|
@ -151,7 +151,7 @@ interface FieldItemInterface extends ComplexDataInterface {
|
|||
* @param $property_name
|
||||
* The name of the property to get; e.g., 'title' or 'name'.
|
||||
*
|
||||
* @return boolean
|
||||
* @return bool
|
||||
* Returns TRUE if the property exists and is set, FALSE otherwise.
|
||||
*/
|
||||
public function __isset($property_name);
|
||||
|
@ -183,26 +183,39 @@ interface FieldItemInterface extends ComplexDataInterface {
|
|||
/**
|
||||
* Defines custom presave behavior for field values.
|
||||
*
|
||||
* This method is called before insert() and update() methods, and before
|
||||
* values are written into storage.
|
||||
* This method is called during the process of saving an entity, just before
|
||||
* values are written into storage. When storing a new entity, its identifier
|
||||
* will not be available yet. This should be used to massage item property
|
||||
* values or perform any other operation that needs to happen before values
|
||||
* are stored. For instance this is the proper phase to auto-create a new
|
||||
* entity for an entity reference field item, because this way it will be
|
||||
* possible to store the referenced entity identifier.
|
||||
*/
|
||||
public function preSave();
|
||||
|
||||
/**
|
||||
* Defines custom insert behavior for field values.
|
||||
* Defines custom post-save behavior for field values.
|
||||
*
|
||||
* This method is called during the process of inserting an entity, just
|
||||
* before values are written into storage.
|
||||
*/
|
||||
public function insert();
|
||||
|
||||
/**
|
||||
* Defines custom update behavior for field values.
|
||||
* This method is called during the process of saving an entity, just after
|
||||
* values are written into storage. This is useful mostly when the business
|
||||
* logic to be implemented always requires the entity identifier, even when
|
||||
* storing a new entity. For instance, when implementing circular entity
|
||||
* references, the referenced entity will be created on pre-save with a dummy
|
||||
* value for the referring entity identifier, which will be updated with the
|
||||
* actual one on post-save.
|
||||
*
|
||||
* This method is called during the process of updating an entity, just before
|
||||
* values are written into storage.
|
||||
* In the rare cases where item properties depend on the entity identifier,
|
||||
* massaging logic will have to be implemented on post-save and returning TRUE
|
||||
* will allow them to be rewritten to the storage with the updated values.
|
||||
*
|
||||
* @param bool $update
|
||||
* Specifies whether the entity is being updated or created.
|
||||
*
|
||||
* @return bool
|
||||
* Whether field items should be rewritten to the storage as a consequence
|
||||
* of the logic implemented by the custom behavior.
|
||||
*/
|
||||
public function update();
|
||||
public function postSave($update);
|
||||
|
||||
/**
|
||||
* Defines custom delete behavior for field values.
|
||||
|
|
|
@ -7,14 +7,12 @@
|
|||
|
||||
namespace Drupal\Core\Field;
|
||||
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Access\AccessResult;
|
||||
use Drupal\Core\Entity\FieldableEntityInterface;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Language\LanguageInterface;
|
||||
use Drupal\Core\Session\AccountInterface;
|
||||
use Drupal\Core\TypedData\DataDefinitionInterface;
|
||||
use Drupal\Core\TypedData\Plugin\DataType\ItemList;
|
||||
use Drupal\Core\TypedData\TypedDataInterface;
|
||||
|
||||
/**
|
||||
* Represents an entity field; that is, a list of field item objects.
|
||||
|
@ -212,15 +210,9 @@ class FieldItemList extends ItemList implements FieldItemListInterface {
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function insert() {
|
||||
$this->delegateMethod('insert');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update() {
|
||||
$this->delegateMethod('update');
|
||||
public function postSave($update) {
|
||||
$result = $this->delegateMethod('postSave', $update);
|
||||
return (bool) array_filter($result);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -240,13 +232,23 @@ class FieldItemList extends ItemList implements FieldItemListInterface {
|
|||
/**
|
||||
* Calls a method on each FieldItem.
|
||||
*
|
||||
* Any argument passed will be forwarded to the invoked method.
|
||||
*
|
||||
* @param string $method
|
||||
* The name of the method.
|
||||
* The name of the method to be invoked.
|
||||
*
|
||||
* @return array
|
||||
* An array of results keyed by delta.
|
||||
*/
|
||||
protected function delegateMethod($method) {
|
||||
foreach ($this->list as $item) {
|
||||
$item->{$method}();
|
||||
$result = [];
|
||||
$args = array_slice(func_get_args(), 1);
|
||||
foreach ($this->list as $delta => $item) {
|
||||
// call_user_func_array() is way slower than a direct call so we avoid
|
||||
// using it if have no parameters.
|
||||
$result[$delta] = $args ? call_user_func_array([$item, $method], $args) : $item->{$method}();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -130,26 +130,29 @@ interface FieldItemListInterface extends ListInterface, AccessibleInterface {
|
|||
/**
|
||||
* Defines custom presave behavior for field values.
|
||||
*
|
||||
* This method is called before either insert() or update() methods, and
|
||||
* before values are written into storage.
|
||||
* This method is called during the process of saving an entity, just before
|
||||
* item values are written into storage.
|
||||
*
|
||||
* @see \Drupal\Core\Field\FieldItemInterface::preSave()
|
||||
*/
|
||||
public function preSave();
|
||||
|
||||
/**
|
||||
* Defines custom insert behavior for field values.
|
||||
* Defines custom post-save behavior for field values.
|
||||
*
|
||||
* This method is called after the save() method, and before values are
|
||||
* written into storage.
|
||||
*/
|
||||
public function insert();
|
||||
|
||||
/**
|
||||
* Defines custom update behavior for field values.
|
||||
* This method is called during the process of saving an entity, just after
|
||||
* item values are written into storage.
|
||||
*
|
||||
* This method is called after the save() method, and before values are
|
||||
* written into storage.
|
||||
* @param bool $update
|
||||
* Specifies whether the entity is being updated or created.
|
||||
*
|
||||
* @return bool
|
||||
* Whether field items should be rewritten to the storage as a consequence
|
||||
* of the logic implemented by the custom behavior.
|
||||
*
|
||||
* @see \Drupal\Core\Field\FieldItemInterface::postSave()
|
||||
*/
|
||||
public function update();
|
||||
public function postSave($update);
|
||||
|
||||
/**
|
||||
* Defines custom delete behavior for field values.
|
||||
|
|
|
@ -46,10 +46,7 @@ class EntityReferenceAutocompleteWidget extends WidgetBase {
|
|||
'#type' => 'radios',
|
||||
'#title' => t('Autocomplete matching'),
|
||||
'#default_value' => $this->getSetting('match_operator'),
|
||||
'#options' => array(
|
||||
'STARTS_WITH' => t('Starts with'),
|
||||
'CONTAINS' => t('Contains'),
|
||||
),
|
||||
'#options' => $this->getMatchOperatorOptions(),
|
||||
'#description' => t('Select the method used to collect autocomplete suggestions. Note that <em>Contains</em> can cause performance issues on sites with thousands of entities.'),
|
||||
);
|
||||
$element['size'] = array(
|
||||
|
@ -74,7 +71,8 @@ class EntityReferenceAutocompleteWidget extends WidgetBase {
|
|||
public function settingsSummary() {
|
||||
$summary = array();
|
||||
|
||||
$summary[] = t('Autocomplete matching: @match_operator', array('@match_operator' => $this->getSetting('match_operator')));
|
||||
$operators = $this->getMatchOperatorOptions();
|
||||
$summary[] = t('Autocomplete matching: @match_operator', array('@match_operator' => $operators[$this->getSetting('match_operator')]));
|
||||
$summary[] = t('Textfield size: !size', array('!size' => $this->getSetting('size')));
|
||||
$placeholder = $this->getSetting('placeholder');
|
||||
if (!empty($placeholder)) {
|
||||
|
@ -181,4 +179,17 @@ class EntityReferenceAutocompleteWidget extends WidgetBase {
|
|||
return isset($settings[$setting_name]) ? $settings[$setting_name] : NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the options for the match operator.
|
||||
*
|
||||
* @return array
|
||||
* List of options.
|
||||
*/
|
||||
protected function getMatchOperatorOptions() {
|
||||
return [
|
||||
'STARTS_WITH' => t('Starts with'),
|
||||
'CONTAINS' => t('Contains'),
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ use Drupal\Component\Utility\NestedArray;
|
|||
use Drupal\Component\Utility\SortArray;
|
||||
use Drupal\Component\Utility\SafeMarkup;
|
||||
use Drupal\Core\Form\FormStateInterface;
|
||||
use Drupal\Core\Render\Element;
|
||||
use Symfony\Component\Validator\ConstraintViolationInterface;
|
||||
use Symfony\Component\Validator\ConstraintViolationListInterface;
|
||||
|
||||
|
@ -415,8 +416,8 @@ abstract class WidgetBase extends PluginSettingsBase implements WidgetInterface
|
|||
}
|
||||
}
|
||||
|
||||
// Only set errors if the element is accessible.
|
||||
if (!isset($element['#access']) || $element['#access']) {
|
||||
// Only set errors if the element is visible.
|
||||
if (Element::isVisibleElement($element)) {
|
||||
$handles_multiple = $this->handlesMultipleValues();
|
||||
|
||||
$violations_by_delta = array();
|
||||
|
|
Reference in a new issue