Motivations, Idea for the API v5:

Instead of declaring persistent properties in ->values() function, and need to pass the $bean to every functions, this should be done at class instance level.

Proposed resolution

Before:

<?php
  /**
   * Declares default block settings.
   *
   * Allows the image to be displayed either left or right.
   */
  public function values() {
    $values = array(
      'image' => array(
        'class' => 'block-left',
      ),
    );

    return array_merge(parent::values(), $values);
  }
?>

After:

<?php
class XXX extends Bean {
  /*
   * Allows the image to be displayed either left or right.
   */
  protected $image = array('class' => 'block-left');
}
?>

In the ->form() function and ->view() function, the use of bean is not useful anymore. Before:

<?php
  /**
   * Builds extra settings for the block edit form.
   */
  public function form($bean, $form, &$form_state) {
    $form['position'] = array(
      '#type' => 'radios',
      '#title' => t('Image position'),
      '#options' => array('block-left' => t('Left'), 'block-right' => t('Right')),
      '#default_value' => $bean->image['class'],
      '#description' => t('The position of the image to be displayed on the block.'),
    );

    return $form;
  }
?>

After:

<?php
  /**
   * Builds extra settings for the block edit form.
   */
  public function form($form, &$form_state) {
    $form['position'] = array(
      '#type' => 'radios',
      '#title' => t('Image position'),
      '#options' => array('block-left' => t('Left'), 'block-right' => t('Right')),
      '#default_value' => $this->image['class'],
      '#description' => t('The position of the image to be displayed on the block.'),
    );

    return $form;
  }
?>

This has the effect of simplifying function signatures by removing one argument, and simplifying bean definition by removing a method.

Moreover, the concept of class encapsulating data and methods is better respected, and "data" belongs to the instance level rather than navigating through functions.

See the technical possibility of this and work on a patch if approved.

Comments

indytechcook’s picture

Issue tags: +bean 2

This would be good for bean 2.x. I tagged appropriately.

indytechcook’s picture

Issue summary: View changes

typo