Same name and namespace in other branches
- 3.0.x src/Feeds/Target/Color.php \Drupal\color_field\Feeds\Target\Color
- 8.x-1.x src/Color.php \Drupal\color_field\Color
Defines a color field mapper.
Plugin annotation
@FeedsTarget(
id = "color",
field_types = {
"color_field_type"
}
)
Hierarchy
- class \Drupal\color_field\Feeds\Target\Color extends \Drupal\feeds\Plugin\Type\Target\FieldTargetBase implements \Drupal\feeds\Plugin\Type\Target\ConfigurableTargetInterface
Expanded class hierarchy of Color
6 string references to 'Color'
- ColorFieldType::mainPropertyName dans src/
Plugin/ Field/ FieldType/ ColorFieldType.php - ColorFieldType::propertyDefinitions dans src/
Plugin/ Field/ FieldType/ ColorFieldType.php - ColorFieldType::schema dans src/
Plugin/ Field/ FieldType/ ColorFieldType.php - ColorFieldWidgetBase::formElement dans src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetBase.php - ColorFieldWidgetHTML5::formElement dans src/
Plugin/ Field/ FieldWidget/ ColorFieldWidgetHTML5.php
Fichier
-
src/
Feeds/ Target/ Color.php, line 21
Namespace
Drupal\color_field\Feeds\TargetView source
class Color extends FieldTargetBase implements ConfigurableTargetInterface {
/**
* {@inheritdoc}
*/
protected static function prepareTarget(FieldDefinitionInterface $field_definition) {
return FieldTargetDefinition::createFromFieldDefinition($field_definition)->addProperty('color')
->addProperty('opacity');
}
/**
* {@inheritdoc}
*/
protected function prepareValue($delta, array &$values) {
// Clean up data and format it.
$color = trim($values['color']);
if (substr($color, 0, 1) === '#') {
$color = substr($color, 1);
}
switch ($this->configuration['format']) {
case '#HEXHEX':
$color = '#' . strtoupper($color);
break;
case 'HEXHEX':
$color = strtoupper($color);
break;
case '#hexhex':
$color = '#' . strtolower($color);
break;
case 'hexhex':
$color = strtolower($color);
break;
}
$values['color'] = $color;
$values['opacity'] = $values['opacity'] ? (double) $values['opacity'] : 0.0;
}
/**
* {@inheritdoc}
*/
public function defaultConfiguration() {
return parent::defaultConfiguration() + [
'format' => '#hexhex',
];
}
/**
* {@inheritdoc}
*/
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = parent::buildConfigurationForm($form, $form_state);
$form['format'] = [
'#type' => 'select',
'#title' => $this->t('Format'),
'#options' => [
'#HEXHEX' => $this->t('#123ABC'),
'HEXHEX' => $this->t('123ABC'),
'#hexhex' => $this->t('#123abc'),
'hexhex' => $this->t('123abc'),
],
'#default_value' => $this->configuration['format'],
];
return $form;
}
/**
* {@inheritdoc}
*/
public function getSummary() {
$summary = parent::getSummary();
$summary[] = $this->configuration['format'] ? $summary[] = $this->t('Color with format: %format', [
'%format' => $this->configuration['format'],
]) : $this->t('Color by default');
return $summary;
}
}
Members
Titre Trier par ordre décroissant | Modifiers | Object type | Résumé |
---|---|---|---|
Color::buildConfigurationForm | public | function | |
Color::defaultConfiguration | public | function | |
Color::getSummary | public | function | |
Color::prepareTarget | protected static | function | |
Color::prepareValue | protected | function |