BehaviorSettings.php in Rabbit Hole 2.x
File
src/Entity/BehaviorSettings.php
View source
<?php
namespace Drupal\rabbit_hole\Entity;
use Drupal\Core\Config\Entity\ConfigEntityBase;
use Drupal\rabbit_hole\BehaviorSettingsInterface;
use Drupal\rabbit_hole\Exception\InvalidBehaviorSettingException;
class BehaviorSettings extends ConfigEntityBase implements BehaviorSettingsInterface {
const OVERRIDE_ALLOW = TRUE;
const OVERRIDE_DISALLOW = FALSE;
const REDIRECT_NOT_APPLICABLE = 0;
const REDIRECT_MOVED_PERMANENTLY = 301;
const REDIRECT_FOUND = 302;
const REDIRECT_SEE_OTHER = 303;
const REDIRECT_NOT_MODIFIED = 304;
const REDIRECT_USE_PROXY = 305;
const REDIRECT_TEMPORARY_REDIRECT = 307;
protected $id;
protected $action;
protected $allow_override;
protected $redirect;
protected $redirect_code;
protected $entity_type_id;
protected $entity_id;
public function setAction($action) {
$this->action = $action;
}
public function getAction() {
return $this->action;
}
public function setAllowOverride($allow_override) {
if (!is_bool($allow_override)) {
throw new InvalidBehaviorSettingException('allow_override');
}
$this->allow_override = $allow_override;
}
public function getAllowOverride() {
return $this->allow_override;
}
public function setRedirectCode($redirect_code) {
if (!in_array($redirect_code, [
self::REDIRECT_NOT_APPLICABLE,
self::REDIRECT_MOVED_PERMANENTLY,
self::REDIRECT_FOUND,
self::REDIRECT_SEE_OTHER,
self::REDIRECT_NOT_MODIFIED,
self::REDIRECT_USE_PROXY,
self::REDIRECT_TEMPORARY_REDIRECT,
])) {
throw new InvalidBehaviorSettingException('redirect_code');
}
if ($this->action !== 'redirect' && $redirect_code !== self::REDIRECT_NOT_APPLICABLE) {
throw new InvalidBehaviorSettingException('redirect_code');
}
$this->redirect_code = $redirect_code;
}
public function getRedirectCode() {
return $this->redirect_code;
}
public function setRedirectPath($redirect) {
if ($this->action !== 'redirect' && $redirect != "") {
throw new InvalidBehaviorSettingException('redirect');
}
$this->redirect = $redirect;
}
public function getRedirectPath() {
return $this->redirect;
}
public function calculateDependencies() {
parent::calculateDependencies();
if ($this->entity_type_id && $this->entity_id) {
$bundle = \Drupal::entityTypeManager()
->getDefinition($this->entity_type_id);
$entity_type = \Drupal::entityTypeManager()
->getDefinition($bundle
->getBundleOf());
$bundle_config_dependency = $entity_type
->getBundleConfigDependency($this->entity_id);
$this
->addDependency($bundle_config_dependency['type'], $bundle_config_dependency['name']);
}
return $this;
}
}