/** * Checks if the passed value is valid. * * @param SiteInterface $value The value that should be validated * @param UniqueMainAlias|Constraint $constraint The constraint for the validation * * @api */ public function validate($value, Constraint $constraint) { $result = $this->repository->findOneBySiteId($value->getSiteId()); if (null !== $result && $result->getId() !== $value->getId()) { $this->context->buildViolation($constraint->message)->atPath('siteId')->addViolation(); } }
/** * @param SiteInterface $site * * @return FacadeInterface * * @throws TransformerParameterTypeException */ public function transform($site) { if (!$site instanceof SiteInterface) { throw new TransformerParameterTypeException(); } $facade = $this->newFacade(); $facade->id = $site->getId(); $facade->siteId = $site->getSiteId(); $facade->name = $site->getName(); if ($this->hasGroup(CMSGroupContext::THEME)) { $facade->theme = $this->getTransformer('theme')->transform($site->getTheme()); } if ($this->hasGroup(CMSGroupContext::SITE_MAIN_ALIAS)) { $facade->mainAlias = $this->getTransformer('site_alias')->transform($site->getMainAlias()); } foreach ($site->getLanguages() as $language) { $facade->addLanguage($language); } if ($this->hasGroup(CMSGroupContext::BLOCKS)) { foreach ($site->getBlocks() as $value) { $facade->addBlocks($value); } } $facade->addLink('_self', $this->generateRoute('open_orchestra_api_site_show', array('siteId' => $site->getSiteId()))); if ($this->authorizationChecker->isGranted(AdministrationPanelStrategy::ROLE_ACCESS_DELETE_SITE)) { $facade->addLink('_self_delete', $this->generateRoute('open_orchestra_api_site_delete', array('siteId' => $site->getSiteId()))); } if ($this->authorizationChecker->isGranted(AdministrationPanelStrategy::ROLE_ACCESS_UPDATE_SITE)) { $facade->addLink('_self_form', $this->generateRoute('open_orchestra_backoffice_site_form', array('siteId' => $site->getSiteId()))); } return $facade; }