/** * {@inheritDoc} */ public function validateEntity(EntityInterface $entity, ErrorStore $errorStore) { if (!$entity->getSite()) { $errorStore->addError('o:site', 'A page must belong to a site.'); } $slug = $entity->getSlug(); if (!is_string($slug) || $slug === '') { $errorStore->addError('o:slug', 'The slug cannot be empty.'); } if (preg_match('/[^a-zA-Z0-9-]/u', $slug)) { $errorStore->addError('o:slug', 'A slug can only contain letters, numbers, and hyphens.'); } if ($entity->getSite() && !$this->isUnique($entity, ['slug' => $slug, 'site' => $entity->getSite()])) { $errorStore->addError('o:slug', sprintf('The slug "%s" is already taken.', $slug)); } if (!$entity->getTitle()) { $errorStore->addError('o:title', 'A page must have a title.'); } }