You are here

public static function Event::loadByMachineName in Event 8

Checks that an existing machine name does not already exist.

This is a static method so it can be used by a machine name field.

Parameters

string $machine_name: The machine name to load the entity by.

Return value

\Drupal\event\Entity\Event|array Loaded Link entity or NULL if not found.

File

src/Entity/Event.php, line 241

Class

Event
Defines the Event entity.

Namespace

Drupal\event\Entity

Code

public static function loadByMachineName($machine_name) {
  $storage = \Drupal::service('entity.manager')
    ->getStorage('event');
  $result = $storage
    ->getQuery()
    ->condition('machine_name', $machine_name)
    ->execute();
  return $result ? $storage
    ->loadMultiple($result) : [];
}