本文整理匯總了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);
}