本文整理匯總了PHP中Drupal\Core\Field\FieldDefinitionInterface::getDefaultValueLiteral方法的典型用法代碼示例。如果您正苦於以下問題:PHP FieldDefinitionInterface::getDefaultValueLiteral方法的具體用法?PHP FieldDefinitionInterface::getDefaultValueLiteral怎麽用?PHP FieldDefinitionInterface::getDefaultValueLiteral使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Drupal\Core\Field\FieldDefinitionInterface
的用法示例。
在下文中一共展示了FieldDefinitionInterface::getDefaultValueLiteral方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: onDependencyRemoval
/**
* {@inheritdoc}
*/
public static function onDependencyRemoval(FieldDefinitionInterface $field_definition, array $dependencies)
{
$changed = FALSE;
if ($default_value = $field_definition->getDefaultValueLiteral()) {
$target_entity_type = \Drupal::entityManager()->getDefinition($field_definition->getFieldStorageDefinition()->getSetting('target_type'));
foreach ($default_value as $key => $value) {
if (is_array($value) && isset($value['target_uuid'])) {
$entity = \Drupal::entityManager()->loadEntityByUuid($target_entity_type->id(), $value['target_uuid']);
// @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue()
if ($entity && isset($dependencies[$entity->getConfigDependencyKey()][$entity->getConfigDependencyName()])) {
unset($default_value[$key]);
$changed = TRUE;
}
}
}
if ($changed) {
$field_definition->setDefaultValue($default_value);
}
}
return $changed;
}
示例2: calculateDependencies
/**
* {@inheritdoc}
*/
public static function calculateDependencies(FieldDefinitionInterface $field_definition)
{
$dependencies = [];
if (is_array($field_definition->getDefaultValueLiteral()) && count($field_definition->getDefaultValueLiteral())) {
$target_entity_type = \Drupal::entityManager()->getDefinition($field_definition->getFieldStorageDefinition()->getSetting('target_type'));
foreach ($field_definition->getDefaultValueLiteral() as $default_value) {
if (is_array($default_value) && isset($default_value['target_uuid'])) {
$entity = \Drupal::entityManager()->loadEntityByUuid($target_entity_type->id(), $default_value['target_uuid']);
// If the entity does not exist do not create the dependency.
// @see \Drupal\Core\Field\EntityReferenceFieldItemList::processDefaultValue()
if ($entity) {
$dependencies[$target_entity_type->getConfigDependencyKey()][] = $entity->getConfigDependencyName();
}
}
}
}
return $dependencies;
}