metatag_favicons.mask-icon.class.inc 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * @file
  4. * Custom class for the mask-icon meta tag's custom data.
  5. */
  6. /**
  7. * Mask icon meta tag controller.
  8. */
  9. class DrupalMaskIconMetaTag extends DrupalTextMetaTag {
  10. /**
  11. * {@inheritdoc}
  12. */
  13. public function getForm(array $options = array()) {
  14. $form['value'] = array(
  15. '#type' => 'textfield',
  16. '#title' => $this->info['label'],
  17. '#default_value' => isset($this->data['value']) ? $this->data['value'] : '',
  18. '#description' => isset($this->info['description']) ? $this->info['description'] : '',
  19. '#maxlength' => 1024,
  20. '#weight' => $this->getWeight(),
  21. );
  22. $form['color'] = array(
  23. '#type' => 'textfield',
  24. '#title' => t('Icon: SVG color'),
  25. '#default_value' => isset($this->data['color']) ? $this->data['color'] : '',
  26. '#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')),
  27. '#maxlength' => 10,
  28. '#weight' => $form['value']['#weight'] + 0.01,
  29. );
  30. return $form;
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function getValue(array $options = array()) {
  36. $value = array(
  37. 'value' => '',
  38. 'color' => '',
  39. );
  40. // The 'color' attribute will only be output if the 'value' is present.
  41. if (!empty($this->data['value'])) {
  42. // Pass the 'value' through the parent logic.
  43. $value['value'] = parent::getValue($options);
  44. // Get the optional 'color' attribute.
  45. if (!empty($this->data['color'])) {
  46. $value['color'] = check_plain($this->tidyValue($this->data['color']));
  47. }
  48. }
  49. return $value;
  50. }
  51. /**
  52. * {@inheritdoc}
  53. */
  54. public function getElement(array $options = array()) {
  55. $value = $this->getValue($options);
  56. // This meta tag has two separate values.
  57. $color = $value['color'];
  58. $value = $value['value'];
  59. // Don't bother proceeding if the 'value' is empty.
  60. if (strlen($value) === 0) {
  61. return array();
  62. }
  63. // The stack of elements that will be output.
  64. $elements = array();
  65. // Dynamically add each option to this setting.
  66. $base_element = isset($this->info['element']) ? $this->info['element'] : array();
  67. // Combine the base configuration for this meta tag with the value.
  68. $element = $base_element + array(
  69. '#theme' => 'metatag',
  70. '#tag' => 'link',
  71. '#id' => 'metatag_' . $this->info['name'] . '_' . 1,
  72. '#rel' => $this->info['name'],
  73. '#name' => $this->info['name'],
  74. '#value' => $value,
  75. '#color' => $color,
  76. '#weight' => $this->getWeight(),
  77. );
  78. // Add header information if desired.
  79. if (!empty($this->info['header'])) {
  80. $element['#attached']['drupal_add_http_header'][] = array($this->info['header'], $value);
  81. }
  82. $elements[] = array($element, $element['#id']);
  83. return array(
  84. '#attached' => array('drupal_add_html_head' => $elements),
  85. );
  86. }
  87. }