Skip to content
Snippets Groups Projects

Put each entity type table into a details element on admin/config/regional/content-language

2 files
+ 72
3
Compare changes
  • Side-by-side
  • Inline
Files
2
  • 3eebb1b1
    Issue #2608750 by phenaproxima, shriaas2898, KapilV, mohit_aghera, RenatoG,... · 3eebb1b1
    Lee Rowlands authored
    Issue #2608750 by phenaproxima, shriaas2898, KapilV, mohit_aghera, RenatoG, akhoury, guilhermevp, praveenmoses61, sulfikar_s, Abhijith S, larowlan, pameeela, Sid_omp: Exception when creating an entity reference field targeting an entity type without an ID
@@ -10,6 +10,7 @@
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Entity\TypedData\EntityDataDefinition;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldException;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\PreconfiguredFieldUiOptionsInterface;
@@ -67,6 +68,12 @@ public static function propertyDefinitions(FieldStorageDefinitionInterface $fiel
$settings = $field_definition->getSettings();
$target_type_info = \Drupal::entityTypeManager()->getDefinition($settings['target_type']);
// If the target entity type doesn't have an ID key, we cannot determine
// the target_id data type.
if (!$target_type_info->hasKey('id')) {
throw new FieldException('Entity type "' . $target_type_info->id() . '" has no ID key and cannot be targeted by entity reference field "' . $field_definition->getName() . '"');
}
$target_id_data_type = 'string';
if ($target_type_info->entityClassImplements(FieldableEntityInterface::class)) {
$id_definition = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions($settings['target_type'])[$target_type_info->getKey('id')];
@@ -356,13 +363,23 @@ public function storageSettingsForm(array &$form, FormStateInterface $form_state
$element['target_type'] = [
'#type' => 'select',
'#title' => t('Type of item to reference'),
'#options' => \Drupal::service('entity_type.repository')->getEntityTypeLabels(TRUE),
'#default_value' => $this->getSetting('target_type'),
'#required' => TRUE,
'#disabled' => $has_data,
'#size' => 1,
];
// Only allow the field to target entity types that have an ID key. This
// is enforced in ::propertyDefinitions().
$entity_type_manager = \Drupal::entityTypeManager();
$filter = function (string $entity_type_id) use ($entity_type_manager): bool {
return $entity_type_manager->getDefinition($entity_type_id)
->hasKey('id');
};
$options = \Drupal::service('entity_type.repository')->getEntityTypeLabels(TRUE);
foreach ($options as $group_name => $group) {
$element['target_type']['#options'][$group_name] = array_filter($group, $filter, ARRAY_FILTER_USE_KEY);
}
return $element;
}
@@ -618,8 +635,9 @@ public function getSettableOptions(AccountInterface $account = NULL) {
}
/**
* Render API callback: Processes the field settings form and allows access to
* the form state.
* Render API callback: Processes the field settings form.
*
* Allows access to the form state.
*
* @see static::fieldSettingsForm()
*/
Loading