本文整理汇总了PHP中Drupal\Core\Field\FieldItemListInterface::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP FieldItemListInterface::getValue方法的具体用法?PHP FieldItemListInterface::getValue怎么用?PHP FieldItemListInterface::getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Field\FieldItemListInterface
的用法示例。
在下文中一共展示了FieldItemListInterface::getValue方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getValueFromProperty
/**
* {@inheritdoc}
*/
public function getValueFromProperty(FieldItemListInterface $property, $delta = 0)
{
if ($property->getValue() && $property->getFieldDefinition()->getCardinality() == 1) {
return $property->referencedEntities()[0];
}
return $property->referencedEntities();
}
示例2: formElement
/**
* {@inheritdoc}
*/
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state)
{
$settings = $this->getSettings();
$multiple = $this->fieldDefinition->getFieldStorageDefinition()->isMultiple();
$values = $items->getValue();
if ($multiple) {
$default_value = array_column($values, 'target_id');
} else {
$default_value = !empty($values) ? $values[0]['target_id'] : NULL;
}
$element += ['#type' => 'entity_select', '#target_type' => $this->getFieldSetting('target_type'), '#multiple' => $multiple, '#default_value' => $default_value, '#autocomplete_threshold' => $settings['autocomplete_threshold'], '#autocomplete_size' => $settings['autocomplete_size'], '#autocomplete_placeholder' => $settings['autocomplete_placeholder'], '#required' => $this->fieldDefinition->isRequired()];
return ['target_id' => $element];
}
示例3: getValueFromProperty
/**
* {@inheritdoc}
*/
public function getValueFromProperty(FieldItemListInterface $property)
{
return $property->getValue();
}
示例4: process_field
/**
* Process a field.
*
* @param \Drupal\Core\Field\FieldItemListInterface $field
* @param string $op
* @param boolean $force if set, we don't check if encryption is enabled, we process the field anyway. This is used during batch processes.
*/
protected function process_field(\Drupal\Core\Field\FieldItemListInterface $field, $op = 'encrypt', $force = FALSE)
{
if (!is_callable([$field, 'getFieldDefinition'])) {
return;
}
/**
* @var $definition \Drupal\Core\Field\BaseFieldDefinition
*/
$definition = $field->getFieldDefinition();
if (!is_callable([$definition, 'get'])) {
return;
}
$field_type = $definition->get('field_type');
/**
* Filter out fields that do not have a defined map.
*/
if (!in_array($field_type, array_keys($this->getFieldEncryptMap()))) {
return;
}
/**
* @var $storage \Drupal\Core\Field\FieldConfigStorageBase
*/
$storage = $definition->get('fieldStorage');
if (is_null($storage)) {
return;
}
/**
* If we are using the force flag, we always proceed.
* The force flag is used when we are updating stored fields.
*/
if (!$force) {
/**
* Check if we are updating the field, in that case, skip it now (during
* the initial entity load.
*/
if ($this->updatingStoredField === $definition->get('field_name')) {
return;
}
// Check if the field is encrypted.
$encrypted = $storage->getThirdPartySetting('field_encrypt', 'encrypt', FALSE);
if (!$encrypted) {
return;
}
}
/**
* @var $field \Drupal\Core\Field\FieldItemList
*/
$field_value = $field->getValue();
foreach ($field_value as &$value) {
// Process each of the sub fields that exits.
$map = $this->fieldEncryptMap[$field_type];
foreach ($map as $value_name => $service) {
if (isset($value[$value_name])) {
$value[$value_name] = $this->process_value($value[$value_name], $service, $op);
}
}
}
// Set the new value.
// We don't need to update the entity because the field setValue does that already.
$field->setValue($field_value);
}