ButtonField.php in Button Field 8
File
src/Plugin/Field/FieldType/ButtonField.php
View source
<?php
namespace Drupal\button_field\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
class ButtonField extends FieldItemBase {
public static function defaultSettings() {
$settings = parent::defaultSettings();
$settings['confirmation'] = '';
return $settings;
}
public static function defaultInstanceSettings() {
$settings = parent::defaultInstanceSettings();
$settings['additional_classes'] = '';
return $settings;
}
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'value' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
),
);
}
public function isEmpty() {
return TRUE;
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties['value'] = DataDefinition::create('string')
->setLabel(t('Value'));
return $properties;
}
public function instanceSettingsForm(array $form, array &$form_state) {
$element = array();
$element['additional_classes'] = array(
'#type' => 'textfield',
'#title' => t('Additional classes'),
'#default_value' => $this
->getSetting('additional_classes'),
'#description' => t('Optionally, specify any classes to be applied to the element. All button field elements will always have the "button_field" class. Separate multiple classes with a space.'),
);
return $element;
}
public function settingsForm(array $form, array &$form_state, $has_data) {
$element = array();
$element['confirmation'] = array(
'#type' => 'textfield',
'#title' => t('Confirmation message'),
'#default_value' => $this
->getSetting('confirmation'),
'#description' => t('You may enter a confirmation message to be displayed to the user before running any rules. If you do not want the user to see a confirmation message you can leave this setting empty.'),
);
return $element;
}
}
Classes
Name |
Description |
ButtonField |
Plugin implementation of the 'button_field' field type. |