Sulu\Component\Webspace\Webspace::addDefaultTemplate PHP Method

addDefaultTemplate() public method

Add a new default template for given type.
public addDefaultTemplate ( string $type, string $template )
$type string
$template string
    public function addDefaultTemplate($type, $template)
    {
        $this->defaultTemplates[$type] = $template;
    }

Usage Example

Example #1
0
 /**
  * {@inheritdoc}
  */
 protected function generateDefaultTemplates(Webspace $webspace)
 {
     $expected = ['page', 'home'];
     foreach ($this->xpath->query('/x:webspace/x:default-templates/x:default-template') as $node) {
         /* @var \DOMNode $node */
         $template = $node->nodeValue;
         $type = $node->attributes->getNamedItem('type')->nodeValue;
         $webspace->addDefaultTemplate($type, $template);
         if ($type === 'homepage') {
             $webspace->addDefaultTemplate('home', $template);
         }
     }
     $found = array_keys($webspace->getDefaultTemplates());
     foreach ($expected as $item) {
         if (!in_array($item, $found)) {
             throw new ExpectedDefaultTemplatesNotFound($this->webspace->getKey(), $expected, $found);
         }
     }
     return $webspace;
 }