You are here

public function PatternDefinition::__construct in UI Patterns 8

PatternDefinition constructor.

File

src/Definition/PatternDefinition.php, line 55

Class

PatternDefinition
Class PatternDefinition.

Namespace

Drupal\ui_patterns\Definition

Code

public function __construct(array $definition = []) {
  foreach ($definition as $name => $value) {
    if (array_key_exists($name, $this->definition)) {
      $this->definition[$name] = $value;
    }
    else {
      $this->definition['additional'][$name] = $value;
    }
  }
  $this->id = $this->definition['id'];
  $this
    ->setFields($this->definition['fields']);
  $this
    ->setVariants($this->definition['variants']);
  $this
    ->setThemeHook(self::PATTERN_PREFIX . $this
    ->id());
  if (!empty($definition['theme hook'])) {
    $this
      ->setThemeHook($definition['theme hook']);
    $this->definition['custom theme hook'] = TRUE;
  }
  if (!$this
    ->hasTemplate()) {
    $this
      ->setTemplate(str_replace('_', '-', $this
      ->getThemeHook()));
  }
}