/** * Find a SiteConfiguration entity for the current site * * @return \TYPO3\Neos\GoogleAnalytics\Domain\Model\SiteConfiguration */ public function evaluate() { $node = $this->getNode(); if ($node instanceof NodeInterface) { $contentContext = $node->getContext(); if ($contentContext instanceof \TYPO3\Neos\Domain\Service\ContentContext) { $site = $contentContext->getCurrentSite(); $siteConfiguration = $this->siteConfigurationRepository->findOneBySite($site); return $siteConfiguration; } } return NULL; }
/** * Update or add site configurations * * @param array<\TYPO3\Neos\GoogleAnalytics\Domain\Model\SiteConfiguration> $siteConfigurations Array of site configurations * @return void */ public function updateAction(array $siteConfigurations) { foreach ($siteConfigurations as $siteConfiguration) { if ($this->persistenceManager->isNewObject($siteConfiguration)) { $this->siteConfigurationRepository->add($siteConfiguration); } else { $this->siteConfigurationRepository->update($siteConfiguration); } } $this->emitSiteConfigurationChanged(); $this->addFlashMessage('Configuration has been updated.', 'Update', NULL, array(), 1417109043); $this->redirect('index'); }
/** * Get a site configuration (which has a Google Analytics profile id) for the given node * * This will first look for a SiteConfiguration entity and then fall back to site specific settings. * * @param NodeInterface $node * @return SiteConfiguration * @throws MissingConfigurationException If no site configuration was found, or the profile was not assigned */ protected function getSiteConfigurationByNode(NodeInterface $node) { $context = $node->getContext(); if (!$context instanceof ContentContext) { throw new \InvalidArgumentException(sprintf('Expected a ContentContext instance in the given node, got %s', get_class($context)), 1415722633); } $site = $context->getCurrentSite(); $siteConfiguration = $this->siteConfigurationRepository->findOneBySite($site); if ($siteConfiguration instanceof SiteConfiguration && $siteConfiguration->getProfileId() !== '') { return $siteConfiguration; } else { if (isset($this->sitesSettings[$site->getNodeName()]['profileId']) && (string) $this->sitesSettings[$site->getNodeName()]['profileId'] !== '') { $siteConfiguration = new SiteConfiguration(); $siteConfiguration->setProfileId($this->sitesSettings[$site->getNodeName()]['profileId']); return $siteConfiguration; } throw new MissingConfigurationException('No profile configured for site', 1415806282); } }