TweetbuttonItem.php in Tweet Button 8
File
lib/Drupal/tweetbutton/Plugin/Field/FieldType/TweetbuttonItem.php
View source
<?php
namespace Drupal\tweetbutton\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\TypedData\DataDefinition;
class TweetbuttonItem extends FieldItemBase {
public static function schema(FieldStorageDefinitionInterface $field_definition) {
return array(
'columns' => array(
'text' => array(
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
'account' => array(
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
),
),
'indexes' => array(
'text' => array(
'text',
),
'account' => array(
'account',
),
),
);
}
public function settingsForm(array $form, array &$form_state, $has_data) {
$element = array();
$config = \Drupal::config('tweetbutton.settings');
$settings = $this
->getFieldDefinition()
->getField()
->getSettings();
$element['tweet_text'] = array(
'#type' => 'textfield',
'#title' => t('Tweet text'),
'#default_value' => isset($settings['tweet_text']) ? $settings['tweet_text'] : $config
->get('tweetbutton_tweet_text'),
);
$element['author_twitter'] = array(
'#type' => 'textfield',
'#title' => t('Author twitter account'),
'#default_value' => isset($settings['author_twitter']) ? $settings['author_twitter'] : $config
->get('tweetbutton_account'),
'#description' => t('This user will be @mentioned in the suggested'),
);
return $element;
}
public function isEmpty() {
return FALSE;
}
public function getConstraints() {
$constraint_manager = \Drupal::typedDataManager()
->getValidationConstraintManager();
$constraints = parent::getConstraints();
return $constraints;
}
}