You are here

bean_test.module in Bean (for Drupal 7) 7

Primary hook implementations for the Bean Test module.

File

tests/bean_test.module
View source
<?php

/**
 * @file
 * Primary hook implementations for the Bean Test module.
 */

/**
 * Implements hook_bean_types_api_info().
 */
function bean_test_bean_types_api_info() {
  return array(
    'api' => 4,
  );
}

/**
 * Implements hook_bean_types().
 */
function bean_test_bean_types() {
  $plugins = array();
  $plugins['test_bean'] = array(
    'label' => t('Test'),
    'description' => t('This is a test plugin'),
    'handler' => array(
      'class' => 'BeanTestPlugin',
      'parent' => 'bean',
    ),
  );
  $plugins['test_bean_2'] = array(
    'label' => t('Test 2'),
    'description' => t('This is a test plugin'),
    'handler' => array(
      'class' => 'BeanTestPlugin',
      'parent' => 'bean',
    ),
  );
  $plugins['test_no_bean'] = array(
    'label' => t('Test No Class'),
    'description' => t('This class does not exist'),
    'handler' => array(
      'class' => 'ClassDoesNotExist',
    ),
  );
  $plugins['test_wrong_class'] = array(
    'label' => t('Test Invalid Class'),
    'description' => t('This class does not exist'),
    'handler' => array(
      'class' => 'BeanPluginWrong',
    ),
  );
  return $plugins;
}
class BeanTestPlugin extends BeanPlugin {
  public function values() {
    return array(
      'test_boolean' => TRUE,
      'test_string' => t('String'),
      'test_array' => array(
        'test_array_1' => 'test_array_1',
      ),
    );
  }
  public function form($bean, $form, &$form_state) {
    $form = array();
    $form['test_boolean'] = array(
      '#type' => 'textfield',
      '#title' => t('String'),
      '#default_value' => $bean->test_string,
    );
    $form['test_boolean'] = array(
      '#type' => 'checkbox',
      '#title' => t('Boolean'),
      '#default_value' => $bean->test_boolean,
    );
    $form['test_array'] = array(
      '#type' => 'string',
      '#title' => t('Array'),
      '#default_value' => $bean->test_array['test_array_1'],
    );
    return $form;
  }

}
class BeanPluginWrong {

}