Last active
December 7, 2016 19:17
-
-
Save EclipseGc/f17034c1eb45badc6c824923d93fa856 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\lightning_layout; | |
use Drupal\Core\Entity\Entity\EntityViewDisplay; | |
class PanelizerAwareEntityViewDisplay extends EntityViewDisplay { | |
protected function ensurePanelizerFieldStorage() { | |
$storage = $this->entityTypeManager()->getStorage('field_storage_config'); | |
$entity = $storage->load( | |
$this->getTargetEntityTypeId() . '.panelizer' | |
); | |
if (empty($entity)) { | |
$entity = $storage->create([ | |
'entity_type' => $this->getTargetEntityTypeId(), | |
'field_name' => 'panelizer', | |
'type' => 'panelizer', | |
'cardinality' => -1, | |
'settings' => [], | |
'status' => TRUE, | |
]); | |
$entity->save(); | |
} | |
return $entity; | |
} | |
protected function ensurePanelizerField() { | |
$storage = $this->entityTypeManager()->getStorage('field_config'); | |
$entity = $storage->load( | |
$this->getTargetEntityTypeId() . '.' . $this->getTargetBundle() . '.panelizer' | |
); | |
if (empty($entity)) { | |
$entity = $storage->create([ | |
'field_storage' => $this->ensurePanelizerFieldStorage(), | |
'bundle' => $this->getTargetBundle(), | |
'label' => t('Panelizer'), | |
'settings' => [], | |
]); | |
$entity->save(); | |
} | |
return $entity; | |
} | |
public function isPanelized() { | |
return (bool) $this->getThirdPartySetting('panelizer', 'enable', FALSE); | |
} | |
public function setPanelized($status = TRUE) { | |
$status = (bool) $status; | |
if ($status) { | |
$this->ensurePanelizerField(); | |
} | |
return $this->setThirdPartySetting('panelizer', 'enable', $status); | |
} | |
public function isCustomizable() { | |
return (bool) $this->getThirdPartySetting('panelizer', 'custom', FALSE); | |
} | |
public function setCustomizable($status = TRUE) { | |
return $this->setThirdPartySetting('panelizer', 'custom', (bool) $status); | |
} | |
public function isChooseable() { | |
return (bool) $this->getThirdPartySetting('panelizer', 'allow', FALSE); | |
} | |
public function setChooseable($status = TRUE) { | |
return $this->setThirdPartySetting('panelizer', 'allow', (bool) $status); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment