<?php
// \Drupal\Core\Entity\EntityInterface
interface EntityInterface {
// ...
}
// \Drupal\Core\Entity\OwnerInterface
interface OwnerInterface extends EntityInterface {
// Just a marker interface (for now?).
}
// \Drupal\user\UserInterface
interface UserInterface extends OwnerInterface {
// ...
}
// \Drupal\user\User
class User implements UserInterface {
}
// \Drupal\Core\Entity\OwnedEntityInterface
interface OwnedEntityInterface {
// For callers this work fine when you pass an object whose class implements
// UserInterface. Implementors may need to adapt but this is fine according to
// our current policies (https://www.drupal.org/core/d8-bc-policy):
// "Interfaces follow a similar pattern as above with respect to @api,
// @internal, or neither. However, in case of neither tag, the interface is
// treated as an API for callers but not for implementers."
public function setOwner(OwnerInterface $owner);
// ...
}
// Example class.
class OwnedEntity implements OwnedEntityInterface {
public function setOwner(OwnerInterface $owner) {}
}
/**
* @deprecated
*/
// \Drupal\user\EntityOwnerInterface
interface EntityOwnerInterface extends OwnedEntityInterface {
// This now empty, all methods are in "OwnedEntityInterface".
}
$user = new User();
$entity = new OwnedEntity();
$entity->setOwner($user);
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0