CnpjWidget.php in Brazilian IDs 8
File
src/Plugin/Field/FieldWidget/CnpjWidget.php
View source
<?php
namespace Drupal\brazilian_ids\Plugin\Field\FieldWidget;
use Drupal\Core\Field\Plugin\Field\FieldWidget\StringTextfieldWidget;
use Drupal\Core\Field\FieldDefinitionInterface;
use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Form\FormStateInterface;
class CnpjWidget extends StringTextfieldWidget {
public static function defaultSettings() {
return [
'size' => 18,
] + parent::defaultSettings();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$form = parent::settingsForm($form, $form_state);
return $form;
}
public function settingsSummary() {
$summary = parent::settingsSummary();
return $summary;
}
public function formElement(FieldItemListInterface $items, $delta, array $element, array &$form, FormStateInterface $form_state) {
$element['value'] = $element + array(
'#type' => 'brazilian_ids_cnpj',
'#default_value' => isset($items[$delta]->value) ? $items[$delta]->value : NULL,
'#size' => $this
->getSetting('size'),
'#placeholder' => $this
->getSetting('placeholder'),
'#attributes' => [
'class' => [
'js-text-full',
'text-full',
],
],
);
return $element;
}
}
Classes
Name |
Description |
CnpjWidget |
Field widget for CNPJ number input. It can be used with normal text fields. |