Created
October 8, 2022 15:55
-
-
Save Seorusus/805219e690395bee8d896796d8fc602d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Drupal\basf_twig\BridgeElements\Atom; | |
use Drupal\basf_twig\BridgeElements\ElementInterface; | |
use Drupal\paragraphs\ParagraphInterface; | |
class ListGroup implements ElementInterface { | |
/** | |
* Feature list Icon. | |
* | |
* @var \Drupal\basf_twig\BridgeElements\Atom\Icon|null | |
*/ | |
private ?Icon $icon = NULL; | |
/** | |
* Items of List Group. | |
* | |
* @var array | |
*/ | |
private array $items = []; | |
/** | |
* List Group background. | |
* | |
* @var bool | |
*/ | |
private bool $background = FALSE; | |
/** | |
* Constructs the Atom "List Group" object. | |
*/ | |
private function __construct( | |
array $options = NULL, | |
) { | |
// Copy all options to the object. | |
foreach ($options as $option => $optionValue) { | |
if (property_exists($this, $option)) { | |
$this->$option = $optionValue; | |
} | |
} | |
} | |
/** | |
* Creates List Group object. | |
* | |
* @param \Drupal\paragraphs\ParagraphInterface $paragraph | |
* List Group Paragraph. | |
* | |
* @return static | |
* List Group object. | |
* @throws \Exception | |
*/ | |
public static function create(ParagraphInterface $paragraph): ListGroup { | |
$options = []; | |
if (!$paragraph->field_list_items->isEmpty()) { | |
$options['items'] = ListItem::createFromField($paragraph->field_list_items); | |
} | |
return new self($options); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public function toArray(): array { | |
return array_filter([ | |
'icon' => $this->icon, | |
'items' => $this->getListItem(), | |
'background' => $this->background, | |
]); | |
} | |
/** | |
* Set or delete icon for the List Group. | |
* | |
* @param \Drupal\basf_twig\BridgeElements\Atom\Icon|null $icon | |
* List Group icon. | |
* | |
* @return ListGroup | |
* List Group object. | |
*/ | |
public function setIcon(?Icon $icon): ListGroup { | |
$this->icon = $icon; | |
return $this; | |
} | |
/** | |
* Provides list Items for the entity. | |
* | |
* @return array | |
* list Items or empty array if no list Items here. | |
*/ | |
private function getListItem(): array { | |
return $this->items; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment