You are here

class NodeTypesConfigHandler in Node expire 7.2

NodeTypesConfigHandler class.

Defines config handler for node types.

Hierarchy

Expanded class hierarchy of NodeTypesConfigHandler

1 file declares its use of NodeTypesConfigHandler
CommonHookHandler.php in src/Module/Hook/CommonHookHandler.php
CommonHookHandler class.

File

src/Module/Config/NodeTypesConfigHandler.php, line 16
NodeTypesConfigHandler class.

Namespace

Drupal\node_expire\Module\Config
View source
class NodeTypesConfigHandler {

  /**
   * Array with configs for node types.
   *
   * @var array
   */
  protected $nodeTypeConfigs;

  /**
   * Constructs a NodeTypesConfigHandler object.
   */
  public function __construct() {
    $this
      ->loadConfig();
  }

  /**
   * Loads configuration array.
   */
  public function loadConfig() {
    $this->nodeTypeConfigs = variable_get('node_expire_ntypes', array());
  }

  /**
   * Saves configuration array.
   */
  public function saveConfig() {
    variable_set('node_expire_ntypes', $this->nodeTypeConfigs);
  }

  /**
   * Returns single node type config.
   *
   * @param string $node_type
   *   Node type.
   */
  public function getNodeTypeConfig($node_type) {
    if (isset($this->nodeTypeConfigs[$node_type]) and $n_type_config = $this->nodeTypeConfigs[$node_type]) {
      return $n_type_config;
    }
    else {
      return $this
        ->getNodeTypeConfigDefault();
    }
  }

  /**
   * Returns default node type config.
   */
  protected function getNodeTypeConfigDefault() {
    $config_default = array(
      'enabled' => 1,
      'default' => '2038-01-01',
      'max' => '',
      'required' => 0,
      'action_type' => 0,
    );
    return $config_default;
  }

  /**
   * Returns action type.
   *
   * @param string $node_type
   *   Node type.
   */
  public function getActionType($node_type) {
    $config = $this
      ->getNodeTypeConfig($node_type);
    if (isset($config['action_type'])) {
      $action_type = $config['action_type'];
    }
    else {
      $action_type = 0;
    }
    return $action_type;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
NodeTypesConfigHandler::$nodeTypeConfigs protected property Array with configs for node types.
NodeTypesConfigHandler::getActionType public function Returns action type.
NodeTypesConfigHandler::getNodeTypeConfig public function Returns single node type config.
NodeTypesConfigHandler::getNodeTypeConfigDefault protected function Returns default node type config.
NodeTypesConfigHandler::loadConfig public function Loads configuration array.
NodeTypesConfigHandler::saveConfig public function Saves configuration array.
NodeTypesConfigHandler::__construct public function Constructs a NodeTypesConfigHandler object.