You are here

abstract class BeanPlugin in Bean (for Drupal 7) 7

@file Base Plugin Class

Hierarchy

Expanded class hierarchy of BeanPlugin

1 string reference to 'BeanPlugin'
bean_bean_types in ./bean.module
Implements hook_bean_types().

File

plugins/BeanPlugin.class.php, line 8
Base Plugin Class

View source
abstract class BeanPlugin implements BeanTypePluginInterface {
  protected $plugin_info;
  public $type;

  /**
   * Get Plugin info
   */
  public function getInfo($key = NULL) {
    if (!empty($key) && isset($this->plugin_info[$key])) {
      return $this->plugin_info[$key];
    }
    return $this->plugin_info;
  }

  /**
   * Build the URL string
   */
  public function buildURL() {
    return str_replace('_', '-', $this->type);
  }

  /**
   * Get the label
   */
  public function getLabel() {
    return $this
      ->getInfo('label');
  }

  /**
   * Get the description
   */
  public function getDescription() {
    return $this
      ->getInfo('description');
  }
  public function __construct($plugin_info) {
    $this->plugin_info = $plugin_info;
    $this->type = $plugin_info['name'];
  }

  /**
   * Define the form values and their defaults
   *
   * Be sure to call combine the results form the parent::values() with yours
   */
  public function values() {
    return array(
      'view_mode' => 'default',
    );
  }
  public function form($bean, $form, &$form_state) {
    return array();
  }

  /**
   * Add a Bean to the plugin
   */
  public function setBean($bean) {
    $this->bean = $bean;
  }

  /**
   * Is the bean type editable
   */
  public function isEditable() {
    return $this
      ->getInfo('editable');
  }

  /**
   * THe plugin validation function
   */
  public function validate($values, &$form_state) {
  }

  /**
   * React to the saving of the bean
   */
  public function submit(Bean $bean) {
    return $this;
  }

  /**
   * Return the block content.
   *
   * @param $bean
   *   The bean object being viewed.
   * @param $content
   *   The default content array created by Entity API.  This will include any
   *   fields attached to the entity.
   * @param $view_mode
   *   The view mode passed into $entity->view().
   * @return
   *   Return a renderable content array.
   */
  public function view($bean, $content, $view_mode = 'default', $langcode = NULL) {
    if (!empty($content) && module_exists('contextual')) {
      $content['bean'][$bean
        ->Identifier()]['#contextual_links']['bean'] = array(
        'block',
        array(
          $bean
            ->Identifier(),
          'edit',
        ),
      );
    }
    return $content;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BeanPlugin::$plugin_info protected property
BeanPlugin::$type public property
BeanPlugin::buildURL public function Build the URL string Overrides BeanTypePluginInterface::buildURL
BeanPlugin::form public function The Plugin Form Overrides BeanTypePluginInterface::form 1
BeanPlugin::getDescription public function Get the description Overrides BeanTypePluginInterface::getDescription
BeanPlugin::getInfo public function Get Plugin info Overrides BeanTypePluginInterface::getInfo
BeanPlugin::getLabel public function Get the label Overrides BeanTypePluginInterface::getLabel
BeanPlugin::isEditable public function Is the bean type editable Overrides BeanTypePluginInterface::isEditable
BeanPlugin::setBean public function Add a Bean to the plugin Overrides BeanTypePluginInterface::setBean
BeanPlugin::submit public function React to the saving of the bean Overrides BeanTypePluginInterface::submit
BeanPlugin::validate public function THe plugin validation function Overrides BeanTypePluginInterface::validate
BeanPlugin::values public function Define the form values and their defaults Overrides BeanTypePluginInterface::values 1
BeanPlugin::view public function Return the block content. Overrides BeanTypePluginInterface::view
BeanPlugin::__construct public function Constructor Overrides BeanTypePluginInterface::__construct