Blocktabs.php in Block Tabs 8
File
src/Entity/Blocktabs.php
View source
<?php
namespace Drupal\blocktabs\Entity;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Entity\EntityWithPluginCollectionInterface;
use Drupal\blocktabs\BlocktabsInterface;
use Drupal\blocktabs\TabInterface;
use Drupal\blocktabs\TabPluginCollection;
class Blocktabs extends ConfigEntityBase implements BlocktabsInterface, EntityWithPluginCollectionInterface {
protected $name;
protected $label;
protected $event;
protected $style;
protected $tabs = [];
protected $tabsCollection;
public function id() {
return $this->name;
}
public static function postDelete(EntityStorageInterface $storage, array $entities) {
drupal_flush_all_caches();
}
public function postSave(EntityStorageInterface $storage, $update = TRUE) {
parent::postSave($storage, $update);
if ($update) {
if (!empty($this->original) && $this
->id() !== $this->original
->id()) {
if (!$this
->isSyncing()) {
}
}
else {
}
}
}
public function deleteTab(TabInterface $tab) {
$this
->getTabs()
->removeInstanceId($tab
->getUuid());
$this
->save();
return $this;
}
public function getTab($tab) {
return $this
->getTabs()
->get($tab);
}
public function getTabs() {
if (!$this->tabsCollection) {
$this->tabsCollection = new TabPluginCollection($this
->getTabPluginManager(), $this->tabs);
$this->tabsCollection
->sort();
}
return $this->tabsCollection;
}
public function getPluginCollections() {
return [
'tabs' => $this
->getTabs(),
];
}
public function addTab(array $configuration) {
$configuration['uuid'] = $this
->uuidGenerator()
->generate();
$this
->getTabs()
->addInstanceId($configuration['uuid'], $configuration);
return $configuration['uuid'];
}
public function getName() {
return $this
->get('name');
}
public function setName($name) {
$this
->set('name', $name);
return $this;
}
protected function getTabPluginManager() {
return \Drupal::service('plugin.manager.blocktabs.tab');
}
public function getCacheContexts() {
$contexts = parent::getCacheContexts();
foreach ($this
->getTabs() as $tab) {
$contexts = Cache::mergeContexts($tab
->getCacheContexts());
}
return $contexts;
}
public function getCacheTags() {
$tags = parent::getCacheTags();
foreach ($this
->getTabs() as $tab) {
$tags = Cache::mergeTags($tab
->getCacheTags());
}
return $tags;
}
public function getCacheMaxAge() {
$max_age = parent::getCacheMaxAge();
foreach ($this
->getTabs() as $tab) {
$max_age = Cache::mergeMaxAges($max_age, $tab
->getCacheMaxAge());
}
return $max_age;
}
public function getEvent() {
return $this
->get('event');
}
public function getStyle() {
return $this
->get('style');
}
}
Classes
Name |
Description |
Blocktabs |
Defines a blocktabs configuration entity. |