public function testGetRelatableResourceTypesFromFieldDefinition() { $field_config_storage =
$this->container->
get('entity_type.manager'
)->
getStorage('field_config'
);
static::
assertCount(0,
$this->resourceTypeRepository->
get('node', 'foo'
)->
getRelatableResourceTypesByField('field_relationship'
));
$this->
createEntityReferenceField('node', 'foo', 'field_ref_with_missing_bundle', 'Related entity', 'node', 'default',
[ 'target_bundles' =>
['missing_bundle'
],
]);
$fields =
$field_config_storage->
loadByProperties(['field_name' => 'field_ref_with_missing_bundle'
]);
static::
assertSame(['missing_bundle'
],
$fields['node.foo.field_ref_with_missing_bundle'
]->
getItemDefinition()->
getSetting('handler_settings'
)['target_bundles'
]);
try { $this->resourceTypeRepository->
get('node', 'foo'
)->
getRelatableResourceTypesByField('field_ref_with_missing_bundle'
);
static::
fail('The above code must produce a warning since the "missing_bundle" does not exist.'
);
} catch (Warning
$e) { static::
assertSame( 'The "field_ref_with_missing_bundle" at "node:foo" references the "node:missing_bundle" entity type that does not exist. Please take action.',
$e->
getMessage() );
} }