本文整理汇总了PHP中Drupal\Core\Field\FieldItemBase::setValue方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldItemBase::setValue方法的具体用法?PHP FieldItemBase::setValue怎么用?PHP FieldItemBase::setValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Field\FieldItemBase
的用法示例。
在下文中一共展示了FieldItemBase::setValue方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setValue
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE)
{
if (empty($values['data'])) {
$values['data'] = NULL;
} else {
$deserialized_data = unserialize((string) $values['data']);
$values['data'] = is_array($deserialized_data) ? $deserialized_data : NULL;
}
parent::setValue($values, $notify);
}
示例2: setValue
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE)
{
// Unserialize the values.
// @todo The storage controller should take care of this, see
// SqlContentEntityStorage::loadFieldItems, see
// https://www.drupal.org/node/2414835
if (isset($values['query']) && is_string($values['query'])) {
$values['query'] = unserialize($values['query']);
}
parent::setValue($values, $notify);
}
示例3: setValue
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE)
{
// Treat the values as property value of the first property, if no array is
// given.
if (is_string($values)) {
$values = unserialize($values);
if (!is_array($values)) {
$values = array();
}
}
$values = array('value' => $values);
parent::setValue($values, $notify);
}
示例4: setValue
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE)
{
// Treat the values as property value of the language property, if no array
// is given as this handles language codes and objects.
if (isset($values) && !is_array($values)) {
$this->set('language', $values, $notify);
} else {
// Make sure that the 'language' property gets set as 'value'.
if (isset($values['value']) && !isset($values['language'])) {
$values['language'] = $values['value'];
}
parent::setValue($values, $notify);
}
}
示例5: setValue
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE)
{
// Treat the values as property value of the language property, if no array
// is given as this handles language codes and objects.
if (isset($values) && !is_array($values)) {
// Directly update the property instead of invoking the parent, so that
// the language property can take care of updating the language code
// property.
$this->properties['language']->setValue($values, $notify);
// If notify was FALSE, ensure the value property gets synched.
if (!$notify) {
$this->set('value', $this->properties['language']->getTargetIdentifier(), FALSE);
}
} else {
// Make sure that the 'language' property gets set as 'value'.
if (isset($values['value']) && !isset($values['language'])) {
$values['language'] = $values['value'];
}
parent::setValue($values, $notify);
}
}
示例6: setValue
/**
* Overrides \Drupal\Core\TypedData\FieldItemBase::setValue().
*
* @param array|null $values
* An array of property values.
*/
public function setValue($values, $notify = TRUE)
{
parent::setValue($values);
$this->populateComputedValues();
}
示例7: setValue
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE)
{
// Treat the values as property value of the main property, if no array is
// given.
if (isset($values) && !is_array($values)) {
$values = [static::mainPropertyName() => $values];
}
if (isset($values)) {
$values += ['options' => []];
}
// Unserialize the values.
// @todo The storage controller should take care of this, see
// SqlContentEntityStorage::loadFieldItems, see
// https://www.drupal.org/node/2414835
if (is_string($values['options'])) {
$values['options'] = unserialize($values['options']);
}
parent::setValue($values, $notify);
}
示例8: setValue
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE)
{
if (isset($values) && !is_array($values)) {
// If either a scalar or an object was passed as the value for the item,
// assign it to the 'entity' property since that works for both cases.
$this->set('entity', $values, $notify);
} else {
parent::setValue($values, FALSE);
// Support setting the field item with only one property, but make sure
// values stay in sync if only property is passed.
if (isset($values['target_id']) && !isset($values['entity'])) {
$this->onChange('target_id', FALSE);
} elseif (!isset($values['target_id']) && isset($values['entity'])) {
$this->onChange('entity', FALSE);
} elseif (isset($values['target_id']) && isset($values['entity'])) {
// If both properties are passed, verify the passed values match. The
// only exception we allow is when we have a new entity: in this case
// its actual id and target_id will be different, due to the new entity
// marker.
$entity_id = $this->get('entity')->getTargetIdentifier();
if ($entity_id != $values['target_id'] && ($values['target_id'] != static::$NEW_ENTITY_MARKER || !$this->entity->isNew())) {
throw new \InvalidArgumentException('The target id and entity passed to the entity reference item do not match.');
}
}
// Notify the parent if necessary.
if ($notify && $this->parent) {
$this->parent->onChange($this->getName());
}
}
}
示例9: setValue
/**
* {@inheritdoc}
*/
public function setValue($values, $notify = TRUE)
{
if (isset($values) && !is_array($values)) {
// If either a scalar or an object was passed as the value for the item,
// assign it to the 'entity' property since that works for both cases.
$this->set('entity', $values, $notify);
} else {
parent::setValue($values, FALSE);
// Support setting the field item with only one property, but make sure
// values stay in sync if only property is passed.
// NULL is a valid value, so we use array_key_exists().
if (is_array($values) && array_key_exists('target_id', $values) && !isset($values['entity'])) {
$this->onChange('target_id', FALSE);
} elseif (is_array($values) && !array_key_exists('target_id', $values) && isset($values['entity'])) {
$this->onChange('entity', FALSE);
} elseif (is_array($values) && array_key_exists('target_id', $values) && isset($values['entity'])) {
// If both properties are passed, verify the passed values match. The
// only exception we allow is when we have a new entity: in this case
// its actual id and target_id will be different, due to the new entity
// marker.
$entity_id = $this->get('entity')->getTargetIdentifier();
// If the entity has been saved and we're trying to set both the
// target_id and the entity values with a non-null target ID, then the
// value for target_id should match the ID of the entity value.
if (!$this->entity->isNew() && $values['target_id'] !== NULL && $entity_id !== $values['target_id']) {
throw new \InvalidArgumentException('The target id and entity passed to the entity reference item do not match.');
}
}
// Notify the parent if necessary.
if ($notify && $this->parent) {
$this->parent->onChange($this->getName());
}
}
}