IconField.php in Icon API 8
File
modules/icon_field/src/Plugin/Field/FieldWidget/IconField.php
View source
<?php
namespace Drupal\icon_field\Plugin\Field\FieldWidget;
use Drupal;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
class IconField extends WidgetBase {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$value = isset($items[$delta]->value) ? $items[$delta]->value : '';
$element += array(
'#type' => 'textfield',
'#default_value' => $value,
'#element_validate' => array(
array(
$this,
'validate',
),
),
);
return array(
'icon' => $element,
);
}
public function validate($element, FormStateInterface $form_state) {
$value = $element['#icon'];
if (strlen($value) == 0) {
$form_state
->setValueForElement($element, '');
return;
}
}
}
Classes
Name |
Description |
IconField |
Plugin implementation of the 'icon_default_widget' widget. |