GoogleAdwordsText.php in Google AdWords Conversion Tracking 8
File
src/Plugin/Field/FieldWidget/GoogleAdwordsText.php
View source
<?php
namespace Drupal\google_adwords\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
class GoogleAdwordsText extends WidgetBase {
public static function defaultSettings() {
return array(
'size' => 60,
'placeholder' => 'Google AdWords tracking words',
) + parent::defaultSettings();
}
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element = [];
$element['words'] = $element + array(
'#type' => 'textfield',
'#title' => $this
->getSetting('placeholder'),
'#default_value' => isset($items[$delta]->words) ? $items[$delta]->words : NULL,
'#size' => $this
->getSetting('size'),
'#placeholder' => $this
->getSetting('placeholder'),
'#maxlength' => $this
->getFieldSetting('max_length'),
);
return $element;
}
}