You are here

class EntityLabelEmptyFieldHandler in Empty fields 7.2

Defines EntityLabelEmptyFieldHandler.

Hierarchy

Expanded class hierarchy of EntityLabelEmptyFieldHandler

File

plugins/empty_fields_handler_label.inc, line 10
Contains the EntityLabelEmptyFieldHandler plugin for Empty Fields module.

View source
class EntityLabelEmptyFieldHandler extends EmptyFieldHandler {

  /**
   * Implementation of EmptyFieldText::defaults().
   *
   * @return array
   *   An array of default_values for the form below. Key names must match.
   */
  public function defaults() {
    return array(
      'display' => 'text',
    );
  }

  /**
   * Implementation of EmptyFieldText::form().
   *
   * @return array
   *   A FAPI array to be used in configuration of this empty text plugin.
   */
  public function form($context) {
    $form['display'] = array(
      '#type' => 'radios',
      '#title' => t('Display options'),
      '#default_value' => isset($this->options['display']) ? $this->options['display'] : 'text',
      '#options' => array(
        'text' => t('Text only'),
        'link' => t('Link'),
      ),
      '#required' => TRUE,
    );
    return $form;
  }

  /**
   * Implementation of EmptyFieldText::react().
   *
   * @return string
   *   A rendered string of html for display.
   */
  public function react($context) {
    $title = entity_label($context['entity_type'], $context['entity']);
    switch ($this->options['display']) {
      case 'link':
        if ($url = entity_uri($context['entity_type'], $context['entity'])) {
          return l($title, $url['path'], $url['options']);
        }

      // Fall through.
      case 'text':
      default:
        return check_plain($title);
    }
  }

  /**
   * Implementation of EmptyFieldText:summaryText().
   *
   * @return string
   *   Text for the field formatter settings summary.
   */
  public function summaryText() {
    switch ($this->options['display']) {
      case 'link':
        return t('Uses entity link if empty');
      case 'text':
      default:
        return t('Uses entity label if empty');
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
EmptyFieldHandler::$options public property
EmptyFieldHandler::alterOutput public function Provide a method to alter the output of the plugin.
EmptyFieldHandler::__construct public function Create a new EmptyFieldHandler.
EntityLabelEmptyFieldHandler::defaults public function Implementation of EmptyFieldText::defaults(). Overrides EmptyFieldHandler::defaults
EntityLabelEmptyFieldHandler::form public function Implementation of EmptyFieldText::form(). Overrides EmptyFieldHandler::form
EntityLabelEmptyFieldHandler::react public function Implementation of EmptyFieldText::react(). Overrides EmptyFieldHandler::react
EntityLabelEmptyFieldHandler::summaryText public function Implementation of EmptyFieldText:summaryText(). Overrides EmptyFieldHandler::summaryText