You are here

class DrupalMaskIconMetaTag in Metatag 7

Mask icon meta tag controller.

Hierarchy

Expanded class hierarchy of DrupalMaskIconMetaTag

1 string reference to 'DrupalMaskIconMetaTag'
metatag_favicons_metatag_info in metatag_favicons/metatag_favicons.metatag.inc
Implements hook_metatag_info().

File

metatag_favicons/metatag_favicons.mask-icon.class.inc, line 11
Custom class for the mask-icon meta tag's custom data.

View source
class DrupalMaskIconMetaTag extends DrupalTextMetaTag {

  /**
   * {@inheritdoc}
   */
  public function getForm(array $options = array()) {
    $form['value'] = array(
      '#type' => 'textfield',
      '#title' => $this->info['label'],
      '#default_value' => isset($this->data['value']) ? $this->data['value'] : '',
      '#description' => isset($this->info['description']) ? $this->info['description'] : '',
      '#maxlength' => 1024,
      '#weight' => $this
        ->getWeight(),
    );
    $form['color'] = array(
      '#type' => 'textfield',
      '#title' => t('Icon: SVG color'),
      '#default_value' => isset($this->data['color']) ? $this->data['color'] : '',
      '#description' => t('Provides a color for the SVG icon. Per <a href="@specs_url">Apple\'s specifications</a>, it may be a hexadecimal value (e.g. "#990000"), an RGB value (e.g. "rgb(153, 0, 0)"), or a recognized color-keyword (e.g. "red", "lime", "navy", etc). Will only be output if the SVG icon meta tag has a value.', array(
        '@specs_url' => 'https://developer.apple.com/library/mac/releasenotes/General/WhatsNewInSafari/Articles/Safari_9_0.html#//apple_ref/doc/uid/TP40014305-CH9-SW20',
      )),
      '#maxlength' => 10,
      '#weight' => $form['value']['#weight'] + 0.01,
    );
    return $form;
  }

  /**
   * {@inheritdoc}
   */
  public function getValue(array $options = array()) {
    $value = array(
      'value' => '',
      'color' => NULL,
    );

    // The 'color' attribute will only be output if the 'value' is present.
    if (!empty($this->data['value'])) {

      // Pass the 'value' through the parent logic.
      $value['value'] = parent::getValue($options);

      // Get the optional 'color' attribute.
      if (!empty($this->data['color'])) {
        $value['color'] = check_plain($this
          ->tidyValue($this->data['color']));
      }
    }
    return $value;
  }

  /**
   * {@inheritdoc}
   */
  public function getElement(array $options = array()) {
    $value = $this
      ->getValue($options);

    // This meta tag has two separate values.
    $color = $value['color'];
    $value = $value['value'];

    // Don't bother proceeding if the 'value' is empty.
    if (strlen($value) === 0) {
      return array();
    }

    // The stack of elements that will be output.
    $elements = array();

    // Dynamically add each option to this setting.
    $base_element = isset($this->info['element']) ? $this->info['element'] : array();

    // Combine the base configuration for this meta tag with the value.
    $element = $base_element + array(
      '#theme' => 'metatag',
      '#tag' => 'link',
      '#id' => 'metatag_' . $this->info['name'] . '_' . 1,
      '#rel' => $this->info['name'],
      '#name' => $this->info['name'],
      '#value' => $value,
      '#color' => $color,
      '#weight' => $this
        ->getWeight(),
    );

    // Add header information if desired.
    if (!empty($this->info['header'])) {
      $element['#attached']['drupal_add_http_header'][] = array(
        $this->info['header'],
        $value,
      );
    }
    $elements[] = array(
      $element,
      $element['#id'],
    );
    return array(
      '#attached' => array(
        'drupal_add_html_head' => $elements,
      ),
    );
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DrupalDefaultMetaTag::$data protected property The values submitted for this tag.
DrupalDefaultMetaTag::$info protected property All of the basic information about this tag.
DrupalDefaultMetaTag::$weight protected property This item's weight; used for sorting the output.
DrupalDefaultMetaTag::convertUrlToAbsolute protected function Make sure a given URL is absolute.
DrupalDefaultMetaTag::getWeight public function Calculate the weight of this meta tag. Overrides DrupalMetaTagInterface::getWeight
DrupalDefaultMetaTag::maxlength protected function Identify the maximum length of which strings will be allowed.
DrupalDefaultMetaTag::textSummary public static function Copied from text.module with the following changes:. Overrides DrupalMetaTagInterface::textSummary
DrupalDefaultMetaTag::tidyValue protected function Remove unwanted formatting from a meta tag.
DrupalDefaultMetaTag::truncate protected function Shorten a string to a certain length using ::textSummary().
DrupalDefaultMetaTag::__construct public function Constructor. Overrides DrupalMetaTagInterface::__construct 1
DrupalMaskIconMetaTag::getElement public function Get the HTML tag for this meta tag. Overrides DrupalDefaultMetaTag::getElement
DrupalMaskIconMetaTag::getForm public function Build the form for this meta tag. Overrides DrupalTextMetaTag::getForm
DrupalMaskIconMetaTag::getValue public function Get the string value of this meta tag. Overrides DrupalTextMetaTag::getValue