SmsSendWidget.php in SMS Framework 2.x
File
modules/sms_sendtophone/src/Plugin/Field/FieldWidget/SmsSendWidget.php
View source
<?php
declare (strict_types=1);
namespace Drupal\sms_sendtophone\Plugin\Field\FieldWidget;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\WidgetBase;
use Drupal\Core\Form\FormStateInterface;
class SmsSendWidget extends WidgetBase {
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$field = $this->fieldDefinition;
$element['value'] = $element + [
'#title' => $this
->getSetting('label'),
'#default_value' => $items[$delta]->value,
'#required' => $field
->isRequired(),
'#description' => $this
->getSetting('description'),
'#maxlength' => $field
->getSetting('max_length'),
'#weight' => $this
->getSetting('weight'),
];
if ($this
->getSetting('rows') == 1) {
$element['#type'] = 'textfield';
}
else {
$element['#type'] = 'textarea';
$element['#rows'] = $this
->getSetting('rows');
}
return $element;
}
public static function defaultSettings() {
return [
'rows' => 1,
];
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
$form['rows'] = [
'#type' => 'textfield',
'#title' => $this
->t('Rows'),
'#default_value' => $this->settings['rows'],
'#required' => TRUE,
];
return $form;
}
}
Classes
Name |
Description |
SmsSendWidget |
Plugin implementation of the 'sms_sendtophone' widget. |