Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Berdir on
Change record status:
Published (View all published change records)
Project:
Introduced in branch:
8.x
Introduced in version:
8.0-alpha2-dev
Issue links:
Description:
TypedDataInterface::getType() has been removed. Interface checks should instead be used or methods of a more specific interface.
Before
if ($typed_data->getType() == 'string') {
// Do something.
}
if ($field->getType() == 'field_item:text_with_summary') {
// Do something.
}
After
if ($typed_data instanceof \Drupal\Core\TypedData\Type\StringInterface {
// Do something.
}
if ($field->getFieldDefinition()->getFieldType() == 'text_with_summary') {
// Do something.
}
If you need to introspect types (and so you cannot use instanceof), see the 'type' key in $definition. The getPluginId() method can similarly be useful to get type information.
Impacts:
Module developers