Commit 13eae164 authored by targoo's avatar targoo

add lib folder

parent 0fed39d7
<?php
/**
* @file
* Contains \Drupal\telephone\Plugin\field\formatter\TelephoneLinkFormatter.
*/
namespace Drupal\telephone\Plugin\field\formatter;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Formatter\FormatterBase;
use Drupal\Core\Entity\EntityInterface;
/**
* Plugin implementation of the 'telephone_link' formatter.
*
* @Plugin(
* id = "telephone_link",
* module = "telephone",
* label = @Translation("Telephone link"),
* field_types = {
* "telephone"
* },
* settings = {
* "title" = ""
* }
* )
*/
class TelephoneLinkFormatter extends FormatterBase {
/**
* {@inheritdoc}
*/
public function settingsForm(array $form, array &$form_state) {
$elements['title'] = array(
'#type' => 'textfield',
'#title' => t('Title to replace basic numeric telephone number display.'),
'#default_value' => $this->getSetting('title'),
);
return $elements;
}
/**
* {@inheritdoc}
*/
public function settingsSummary() {
$summary = array();
$settings = $this->getSettings();
if (!empty($settings['title'])) {
$summary[] = t('Link using text: @title', array('@title' => $settings['title']));
}
else {
$summary[] = t('Link using provided telephone number.');
}
return $summary;
}
/**
* {@inheritdoc}
*/
public function prepareView(array $entities, $langcode, array &$items) {
$settings = $this->getSettings();
foreach ($entities as $id => $entity) {
foreach ($items[$id] as &$item) {
// If available, set custom link text.
if (!empty($settings['title'])) {
$item['title'] = $settings['title'];
}
// Otherwise, use telephone number itself as title.
else {
$item['title'] = $item['value'];
}
}
}
}
/**
* {@inheritdoc}
*/
public function viewElements(EntityInterface $entity, $langcode, array $items) {
$element = array();
foreach ($items as $delta => $item) {
// Prepend 'tel:' to the telephone number.
$href = 'tel:' . rawurlencode(preg_replace('/\s+/', '', $item['value']));
// Render each element as link.
$element[$delta] = array(
'#type' => 'link',
'#title' => $item['title'],
'#href' => $href,
'#options' => array('external' => TRUE),
);
}
return $element;
}
}
<?php
/**
* @file
* Contains \Drupal\telephone\Plugin\field\widget\TelephoneDefaultWidget.
*/
namespace Drupal\telephone\Plugin\field\widget;
use Drupal\Component\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
use Drupal\field\Plugin\Type\Widget\WidgetBase;
/**
* Plugin implementation of the 'telephone_default' widget.
*
* @Plugin(
* id = "telephone_default",
* module = "telephone",
* label = @Translation("Telephone number"),
* field_types = {
* "telephone"
* },
* settings = {
* "placeholder" = ""
* }
* )
*/
class TelephoneDefaultWidget extends WidgetBase {
/**
* Implements Drupal\field\Plugin\Type\Widget\WidgetInterface::settingsForm().
*/
public function settingsForm(array $form, array &$form_state) {
$element['placeholder'] = array(
'#type' => 'textfield',
'#title' => t('Placeholder'),
'#default_value' => $this->getSetting('placeholder'),
'#description' => t('Text that will be shown inside the field until a value is entered. This hint is usually a sample value or a brief description of the expected format.'),
);
return $element;
}
/**
* Implements \Drupal\field\Plugin\Type\Widget\WidgetInterface::formElement().
*/
public function formElement(array $items, $delta, array $element, $langcode, array &$form, array &$form_state) {
$element['value'] = $element + array(
'#type' => 'tel',
'#default_value' => isset($items[$delta]['value']) ? $items[$delta]['value'] : NULL,
'#placeholder' => $this->getSetting('placeholder'),
);
return $element;
}
}
<?php
/**
* @file
* Contains \Drupal\color_field\Type\ColorFieldItem.
*/
namespace Drupal\color_field\Type;
use Drupal\Core\Entity\Field\FieldItemBase;
/**
* Defines the 'email_field' entity field item.
*/
class ColorFieldItem extends FieldItemBase {
/**
* Definitions of the contained properties.
*
* @see EmailItem::getPropertyDefinitions()
*
* @var array
*/
static $propertyDefinitions;
/**
* Implements ComplexDataInterface::getPropertyDefinitions().
*/
public function getPropertyDefinitions() {
if (!isset(static::$propertyDefinitions)) {
static::$propertyDefinitions['value'] = array(
'type' => 'color_field',
'label' => t('Color value'),
);
}
return static::$propertyDefinitions;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment