You are here

Filebrowser.php in Filebrowser 8

File

lib/Drupal/filebrowser/Entity/Filebrowser.php
View source
<?php

/**
 * @file
 * Contains \Drupal\filebrowser\Entity\Filebrowser.
 */
namespace Drupal\filebrowser\Entity;

use Drupal\Core\Entity\EntityStorageInterface;
use Drupal\Core\Field\FieldDefinition;
use Drupal\Core\Entity\ContentEntityBase;
use Drupal\filebrowser\FilebrowserInterface;
use Drupal\Core\Entity\EntityTypeInterface;

/**
 * Defines the Filebrowser entity.
 *
 * @ContentEntityType(
 *   id = "filebrowser",
 *   label = @Translation("Filebrowser entity"),
 *   controllers = {
 *     "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
 *     "list" = "Drupal\filebrowser\Entity\Controller\FilebrowserListController",
 *
 *     "form" = {
 *       "add" = "Drupal\filebrowser\Entity\Form\FilebrowserFormController",
 *       "edit" = "Drupal\filebrowser\Entity\Form\FilebrowserFormController",
 *       "delete" = "Drupal\filebrowser\Entity\Form\FilebrowserDeleteForm",
 *     },
 *     "translation" = "Drupal\content_translation\ContentTranslationController"
 *   },
 *   base_table = "filebrowser",
 *   admin_permission = "admin_filebrowser",
 *   fieldable = TRUE,
 *   translatable = TRUE,
 *   entity_keys = {
 *     "id" = "filebrowserid",
 *     "label" = "name",
 *     "uuid" = "uuid"
 *   },
 *   links = {
 *     "edit-form" = "filebrowser.edit",
 *     "admin-form" = "filebrowser.settings",
 *     "delete-form" = "filebrowser.delete"
 *   }
 * )
 */
class Filebrowser extends ContentEntityBase implements FilebrowserInterface {

  /**
   * {@inheritdoc}
   */
  public function id() {
    return $this
      ->get('filebrowserid')->value;
  }

  /**
   * {@inheritdoc}
   */
  public function getFilebrowserField() {
    return $this->filebrowser_field->value;
  }

  /**
   * {@inheritdoc}
   */
  public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
    parent::preCreate($storage_controller, $values);
    $values += array(
      'user_id' => \Drupal::currentUser()
        ->id(),
    );
  }

  /**
   * {@inheritdoc}
   */
  public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
    $fields['fbid'] = FieldDefinition::create('integer')
      ->setLabel(t('ID'))
      ->setDescription(t('The ID of the Filebrowser entity.'))
      ->setReadOnly(TRUE);
    $fields['uuid'] = FieldDefinition::create('uuid')
      ->setLabel(t('UUID'))
      ->setDescription(t('The UUID of the Filebrowser entity.'))
      ->setReadOnly(TRUE);
    $fields['langcode'] = FieldDefinition::create('language')
      ->setLabel(t('Language code'))
      ->setDescription(t('The language code of the Filebrowser entity.'));
    $fields['name'] = FieldDefinition::create('string')
      ->setLabel(t('Name'))
      ->setDescription(t('The name of the Filebrowser entity.'))
      ->setTranslatable(TRUE)
      ->setPropertyConstraints('value', array(
      'Length' => array(
        'max' => 32,
      ),
    ))
      ->setSettings(array(
      'default_value' => '',
      'max_length' => 255,
      'text_processing' => 0,
    ))
      ->setDisplayOptions('view', array(
      'label' => 'above',
      'type' => 'string',
      'weight' => -6,
    ))
      ->setDisplayOptions('form', array(
      'type' => 'string',
      'weight' => -6,
    ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    $fields['type'] = FieldDefinition::create('string')
      ->setLabel(t('Type'))
      ->setDescription(t('The bundle of the Filebrowser entity.'))
      ->setRequired(TRUE);
    $fields['user_id'] = FieldDefinition::create('entity_reference')
      ->setLabel(t('User ID'))
      ->setDescription(t('The ID of the associated user.'))
      ->setSettings(array(
      'target_type' => 'user',
    ))
      ->setTranslatable(TRUE);
    $fields['filebrowser_field'] = FieldDefinition::create('string')
      ->setLabel(t('First Filebrowser Field'))
      ->setDescription(t('One field of the Filebrowser entity.'))
      ->setTranslatable(TRUE)
      ->setPropertyConstraints('value', array(
      'Length' => array(
        'max' => 32,
      ),
    ))
      ->setSettings(array(
      'default_value' => '',
      'max_length' => 255,
      'text_processing' => 0,
    ))
      ->setDisplayOptions('view', array(
      'label' => 'above',
      'type' => 'string',
      'weight' => -5,
    ))
      ->setDisplayOptions('form', array(
      'type' => 'string',
      'weight' => -5,
    ))
      ->setDisplayConfigurable('form', TRUE)
      ->setDisplayConfigurable('view', TRUE);
    return $fields;
  }

}
?>

<?php

Classes

Namesort descending Description
Filebrowser Defines the Filebrowser entity.