Skip to content

Instantly share code, notes, and snippets.

@ghorvat
Created January 11, 2017 10:06
Show Gist options
  • Save ghorvat/731688b47af0c009e01655e5e382d32b to your computer and use it in GitHub Desktop.
Save ghorvat/731688b47af0c009e01655e5e382d32b to your computer and use it in GitHub Desktop.
<?php
namespace Drupal\owl\Plugin\Field\FieldType;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
use Drupal\image\Plugin\Field\FieldType\ImageItem;
/**
* Plugin implementation of the 'owl_item' field type.
*
* @FieldType(
* id = "owl_item",
* label = @Translation("Owl item"),
* module = "owl",
* description = @Translation("Image caption text, for the image's 'caption' attribute."),
* default_widget = "owl_image",
* default_formatter = "owl_field_formatter"
* )
*/
class OwlItem extends ImageItem {
public static function schema(FieldStorageDefinitionInterface $field_definition) {
$schema = parent::schema($field_definition);
$schema['columns']['caption'] = array(
'type' => 'varchar',
'length' => '1024',
'unsigned' => TRUE,
);
return $schema;
}
public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {
$properties = parent::propertyDefinitions($field_definition);
$properties['caption'] = DataDefinition::create('string')
->setLabel(t('Caption'))
->setDescription(t("Image caption text, for the image's 'caption' attribute."));
return $properties;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment