Problem/Motivation
FieldStorageDefinitionInterface::getSetting() and DataDefinitionInterface() both have docs which say:
/**
* Returns the value of a given storage setting.
*
* @param string $setting_name
* The setting name.
*
* @return mixed
* The setting value.
*/
They don't say what happens if the setting name doesn't exist on the data being called. For example, if you have a text field and you do:
$text_field->getSetting('target_type'); // This setting does not exist on text fields and makes no sense!
However, the implementations return NULL in this case.
And there is apparently lots of code in the wild that relies on this behaviour, e.g. this in Commerce:
$definitions = $this->entityFieldManager->getFieldDefinitions('commerce_product_variation', $variation_type_id);
$definitions = array_filter($definitions, function ($definition) {
/** @var \Drupal\Core\Field\FieldDefinitionInterface $definition */
$field_type = $definition->getType();
$target_type = $definition->getSetting('target_type');
return $field_type == 'entity_reference' && $target_type == 'commerce_product_attribute_value';
This behaviour of the methods needs to be documented.
Steps to reproduce
Edit the file core/lib/Drupal/Core/Field/FieldStorageDefinitionInterface.php and go to the getSetting() method.
Edit the file core/lib/Drupal/Core/TypedData/DataDefinitionInterface.php and go to the getSetting() method.
Proposed resolution
Add documentation if the setting name doesn't exist to both method.
Remaining tasks
- Fix issue
- Community Review
- Commit
User interface changes
API changes
Data model changes
Release notes snippet