Skip to content

Commit

Permalink
Added ability to add modifiers programmatically
Browse files Browse the repository at this point in the history
  • Loading branch information
voidgraphics authored Oct 29, 2020
1 parent e9a16ad commit 15d7708
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/BemComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,16 @@ protected function processClasses($classes)
*/
protected function getModifiers()
{
if(is_null($this->modifiers)) {
if(! is_null($this->attributes)) {
$modifiers = $this->attributes->get('modifiers');
$this->modifiers = $this->processModifiers($modifiers);

$this->modifiers = array_merge(
$this->processModifiers($modifiers),
$this->modifiers ?? []
);
}

return $this->modifiers;
return $this->modifiers ?? [];
}

/**
Expand Down Expand Up @@ -104,4 +108,37 @@ public function hasClass($classname)
return in_array($classname, $this->getClasses());
}

/**
* Set a modifier programmatically
*
* @param string $modifier
* @return void
*/
public function modifier(string $modifier)
{
if (is_null($this->modifiers)) {
$this->modifiers = [];
}

$this->modifiers[] = $modifier;
}

/**
* Set multiple modifiers programmatically
*
* @param array $modifiers
* @param boolean $overwrite
* @return void
*/
public function modifiers(array $modifiers, $overwrite = false)
{
if ($overwrite) {
$this->modifiers = $modifiers;

return;
}

$this->modifiers = array_merge($this->getModifiers(), $modifiers);
}

}

0 comments on commit 15d7708

Please sign in to comment.