Skip to content

Drupal\helper\EntityHelper

Provides helpers for working with entities.

Methods

Name Description
__construct Constructs an EntityHelper.
hasValue Checks to if an entity's field is available and is not empty.
matchesPath Checks to see if the entity matches a given path.

EntityHelper::__construct

Description

public __construct (\Drupal\Core\Path\PathValidatorInterface $pathValidator)

Constructs an EntityHelper.

Parameters

  • (\Drupal\Core\Path\PathValidatorInterface) $pathValidator :
    The path validator.

Return Values

void


EntityHelper::hasValue

Description

public static hasValue (\Drupal\Core\Entity\EntityInterface $entity, string $fieldName)

Checks to if an entity's field is available and is not empty.

Parameters

  • (\Drupal\Core\Entity\EntityInterface) $entity :
    The entity.
  • (string) $fieldName :
    The field name.

Return Values

bool

TRUE if the field is not empty, FALSE otherwise.


EntityHelper::matchesPath

Description

public matchesPath (\Drupal\Core\Entity\EntityInterface $entity, string $path, string|null $rel, array $options)

Checks to see if the entity matches a given path.

Note, this does not validate that the user can access the path.

Parameters

  • (\Drupal\Core\Entity\EntityInterface) $entity :
    The entity.
  • (string) $path :
    The path to check.
  • (string|null) $rel :
    The parameter to pass as the first argument to EntityInterface::toUrl().
  • (array) $options :
    The parameter to pass as the second argument to EntityInterface::toUrl().

Return Values

bool

TRUE if the entity matches the path, FALSE otherwise.