Issue #3128190 by phthlaap, Keshav Patel, msuthars, sja112, rlmumford, Prashant.c, smustgrave, quietone: FieldItemDataDefinition::getLabel() should show the label of the field type
(cherry picked from commit 94b03bcdec
)
merge-requests/6880/head
parent
c57ce025c3
commit
973d283bea
|
@ -87,4 +87,19 @@ class FieldItemDataDefinition extends DataDefinition implements FieldItemDataDef
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the label of the field type.
|
||||||
|
*
|
||||||
|
* If the label hasn't been set, then fall back to the label of the
|
||||||
|
* typed data definition.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
* The label of the field type.
|
||||||
|
*
|
||||||
|
* @throws \Drupal\Component\Plugin\Exception\PluginNotFoundException
|
||||||
|
*/
|
||||||
|
public function getLabel() {
|
||||||
|
return parent::getLabel() ?: $this->getTypedDataManager()->getDefinition($this->getDataType())['label'];
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,4 +99,16 @@ class FieldItemTest extends EntityKernelTestBase {
|
||||||
$this->assertEquals($expected_value, $entity->{$this->fieldName}->value);
|
$this->assertEquals($expected_value, $entity->{$this->fieldName}->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests \Drupal\Core\Field\TypedData\FieldItemDataDefinition::getLabel().
|
||||||
|
*/
|
||||||
|
public function testGetLabel(): void {
|
||||||
|
$data_definition = \Drupal::service('typed_data_manager')->createDataDefinition('field_item:string');
|
||||||
|
$this->assertEquals('Text (plain)', $data_definition->getLabel());
|
||||||
|
|
||||||
|
$label = 'Foo bar';
|
||||||
|
$data_definition->setLabel($label);
|
||||||
|
$this->assertEquals($label, $data_definition->getLabel());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue