File: D:/HostingSpaces/SBogers10/ste.komma.pro/vendor/komma/kms/src/Core/Sections/Tabs/SectionTab.php
<?php namespace Komma\KMS\Core\Sections\Tabs;
use Komma\KMS\Core\Attributes\Attribute;
use Illuminate\Support\Collection;
use Illuminate\Support\MessageBag;
/**
* Class SectionTab
*
* Represents one of the tabs off a section.
*
* @package App\Kms\Core\Sections
*/
class SectionTab implements SectionTabInterface
{
/** @var string */
private $name;
/** @var Collection */
private $items;
/** @var bool $isLanguageTab */
private $isLanguageTab;
/**
* SectionTab constructor.
* @param string $name
*/
public function __construct(string $name)
{
$this->name = $name;
$this->items = new Collection();
$this->isLanguageTab = false;
}
/**
* @return string
*/
public function getName(): string
{
return $this->name;
}
/**
* @return Collection of SectionTabItems
*/
public function getItems(): Collection
{
return $this->items;
}
/**
* @return SectionTabInterface
*/
public function clearItems(): SectionTabInterface {
$this->items = new Collection();
return $this;
}
/**
* @param $item
* @return SectionTabInterface
*/
public function addItem($item):SectionTabInterface
{
$this->items->push($item);
return $this;
}
/**
* @param Collection $items
* @return SectionTabInterface
*/
public function setItems(Collection $items): SectionTabInterface
{
$this->items = $items;
return $this;
}
/**
* @return bool
*/
public function isLanguageTab(): bool
{
return $this->isLanguageTab;
}
/**
* @param bool $isLanguageTab
* @return SectionTab
*/
public function setIsLanguageTab(bool $isLanguageTab): SectionTab
{
$this->isLanguageTab = $isLanguageTab;
return $this;
}
/**
* For determining if the tab has an error or not.
*
* @param MessageBag $messageBag
* @return bool
*/
public function hasErrors(MessageBag $messageBag): bool
{
$hasErrors = false;
$this->items->each(function($item) use(&$hasErrors, $messageBag) {
if(is_a($item, Attribute::class)) {
/** @var Attribute $item */
if($messageBag->has((string) $item->getKey())) {
$hasErrors = true;
}
}
});
return $hasErrors;
}
}