ButtonFieldHtml.php in Button Field 8
File
src/Plugin/Field/FieldWidget/ButtonFieldHtml.php
View source
<?php
namespace Drupal\button_field\Plugin\Field\FieldWidget;
use Drupal\Core\Form\FormStateInterface;
class ButtonFieldHtml extends ButtonFieldBase {
public static function defaultSettings() {
return array(
'text' => '',
) + parent::defaultSettings();
}
public function settingsForm(array $form, FormStateInterface $form_state) {
$element = parent::settingsForm($form, $form_state);
$element['text'] = array(
'#type' => 'textfield',
'#title' => t('Button Text'),
'#default_value' => $this
->getSetting('text') ?: $this->fieldDefinition
->getLabel(),
'#required' => TRUE,
);
return $element;
}
public function settingsSummary() {
$summary = array();
$summary[] = t('Button title: !text', array(
'!text' => $this
->getSetting('text') ?: $this->fieldDefinition
->getLabel(),
));
return $summary;
}
protected function elementProperties() {
return array(
'#type' => 'button',
'#value' => $this
->getSetting('text') ?: $this->fieldDefinition
->getLabel(),
);
}
}