You are here

CmisField.php in CMIS API 8.2

File

src/Plugin/Field/FieldType/CmisField.php
View source
<?php

declare (strict_types=1);
namespace Drupal\cmis\Plugin\Field\FieldType;

use Drupal\Core\Field\FieldItemBase;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;

/**
 * Plugin implementation of the 'cmis_field' field type.
 *
 * @FieldType(
 *   id = "cmis_field",
 *   label = @Translation("Cmis Field"),
 *   description = @Translation("Attach a CMIS object to a Drupal entity"),
 *   default_widget = "cmis_field_widget",
 *   default_formatter = "cmis_field_link"
 * )
 */
class CmisField extends FieldItemBase {

  /**
   * {@inheritdoc}
   */
  public static function schema(FieldStorageDefinitionInterface $field_definition) {
    return [
      'columns' => [
        'title' => [
          'type' => 'varchar',
          'length' => 255,
        ],
        'path' => [
          'type' => 'varchar',
          'length' => 255,
        ],
      ],
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function isEmpty() {
    $value1 = $this
      ->get('title')
      ->getValue();
    $value2 = $this
      ->get('path')
      ->getValue();
    return empty($value1) && empty($value2);
  }

  /**
   * {@inheritdoc}
   */
  public static function propertyDefinitions(FieldStorageDefinitionInterface $field_definition) {

    // Add our properties.
    $properties['title'] = DataDefinition::create('string')
      ->setLabel(t('Title'))
      ->setDescription(t('The title of CMIS object.'));
    $properties['path'] = DataDefinition::create('string')
      ->setLabel(t('Path'))
      ->setDescription(t('The path of CMIS object.'));
    return $properties;
  }

}

Classes

Namesort descending Description
CmisField Plugin implementation of the 'cmis_field' field type.