소스 검색

Development on Entities

logicp 7 년 전
부모
커밋
ac37581e80
5개의 변경된 파일153개의 추가작업 그리고 2개의 파일을 삭제
  1. 6 0
      config/schema/status_type.schema.yml
  2. 71 2
      src/Entity/Status.php
  3. 51 0
      src/Entity/StatusType.php
  4. 16 0
      src/StatusInterface.php
  5. 9 0
      src/StatusTypeInterface.php

+ 6 - 0
config/schema/status_type.schema.yml

@@ -8,5 +8,11 @@ statusmessage.status_type.*:
     label:
       type: label
       label: 'Label'
+    media:
+      type: boolean
+      label: 'media'
+    mime:
+      type: string
+      label: 'mime'
     uuid:
       type: string

+ 71 - 2
src/Entity/Status.php

@@ -42,7 +42,7 @@ use Drupal\user\UserInterface;
  *     "bundle" = "type",
  *     "label" = "name",
  *     "uuid" = "uuid",
- *     "uid" = "user_id",
+ *     "uid" = "uid",
  *     "langcode" = "langcode",
  *     "status" = "status",
  *   },
@@ -169,7 +169,7 @@ class Status extends ContentEntityBase implements StatusInterface {
       ->setDescription(t('The UUID of the Status entity.'))
       ->setReadOnly(TRUE);
 
-    $fields['user_id'] = BaseFieldDefinition::create('entity_reference')
+    $fields['uid'] = BaseFieldDefinition::create('entity_reference')
       ->setLabel(t('Authored by'))
       ->setDescription(t('The user ID of author of the Status entity.'))
       ->setRevisionable(TRUE)
@@ -195,6 +195,39 @@ class Status extends ContentEntityBase implements StatusInterface {
       ->setDisplayConfigurable('form', TRUE)
       ->setDisplayConfigurable('view', TRUE);
 
+    $fields['recipient'] = BaseFieldDefinition::create('entity_reference')
+      ->setLabel(t('Received by'))
+      ->setDescription(t('The user ID of recipient of the Status entity.'))
+      ->setRevisionable(TRUE)
+      ->setSetting('target_type', 'user')
+      ->setSetting('handler', 'default')
+      ->setTranslatable(TRUE)
+      ->setDisplayOptions('view', array(
+        'label' => 'hidden',
+        'type' => 'author',
+        'weight' => 0,
+      ))
+      ->setDisplayOptions('form', array(
+        'type' => 'entity_reference_autocomplete',
+        'weight' => 5,
+        'settings' => array(
+          'match_operator' => 'CONTAINS',
+          'size' => '60',
+          'autocomplete_type' => 'tags',
+          'placeholder' => '',
+        ),
+      ))
+      ->setDisplayConfigurable('form', TRUE)
+      ->setDisplayConfigurable('view', TRUE);
+
+
+    $fields['entity_target'] = BaseFieldDefinition::create('entity_reference')
+      ->setLabel(t('Node'))
+      ->setDescription(t('The content associated with this Status message'))
+      ->setSetting('target_type', 'node')
+      ->setSetting('handler', 'default')
+      ->setRevisionable(TRUE);
+
     $fields['name'] = BaseFieldDefinition::create('string')
       ->setLabel(t('Name'))
       ->setDescription(t('The name of the Status entity.'))
@@ -215,6 +248,11 @@ class Status extends ContentEntityBase implements StatusInterface {
       ->setDisplayConfigurable('form', TRUE)
       ->setDisplayConfigurable('view', TRUE);
 
+    $fields['message'] = BaseFieldDefinition::create('string_long')
+      ->setLabel(t('Message'))
+      ->setDescription(t('The message of the Status entity.'))
+      ->setRevisionable(TRUE);
+
     $fields['status'] = BaseFieldDefinition::create('boolean')
       ->setLabel(t('Publishing status'))
       ->setDescription(t('A boolean indicating whether the Status is published.'))
@@ -240,4 +278,35 @@ class Status extends ContentEntityBase implements StatusInterface {
     return $fields;
   }
 
+  public function setMessage($message) {
+    $this->set('message', $message);
+  }
+
+  public function getMessage() {
+    return $this->get('message');
+  }
+
+//  public function setSender($sender) {
+//    $this->set('sender', $sender);
+//  }
+//
+//  public function getSender() {
+//    return $this->get('sender');
+//  }
+
+  public function setRecipient($recipient) {
+    $this->set('recipient', $recipient);
+  }
+
+  public function getRecipient() {
+    return $this->get('recipient');
+  }
+
+  public function setEntityTarget($entityTarget) {
+    $this->set('entity_target', $entityTarget);
+  }
+
+  public function getEntityTarget() {
+    return $this->get('entity_target');
+  }
 }

+ 51 - 0
src/Entity/StatusType.php

@@ -54,4 +54,55 @@ class StatusType extends ConfigEntityBundleBase implements StatusTypeInterface {
    */
   protected $label;
 
+
+  /**
+   * Boolean value to determine whether this type contains media
+   *
+   * @var
+   */
+  protected $media;
+
+
+  /**
+   * Mime type for media, if present
+   *
+   * @var
+   */
+  protected $mime;
+
+
+  /**
+   * @param $bool
+   */
+
+  public function setMedia($bool) {
+    $this->set('media', $bool);
+  }
+
+
+  /**
+   * @return mixed|null
+   */
+
+  public function getMedia() {
+    return $this->get('media');
+  }
+
+
+  /**
+   * @param $mime
+   */
+
+  public function setMime($mime) {
+    $this->set('mime', $mime);
+  }
+
+
+  /**
+   * @return mixed|null
+   */
+
+  public function getMime() {
+    return $this->get('mime');
+  }
 }

+ 16 - 0
src/StatusInterface.php

@@ -80,4 +80,20 @@ interface StatusInterface extends ContentEntityInterface, EntityChangedInterface
    */
   public function setPublished($published);
 
+  public function setMessage($message);
+
+  public function getMessage();
+
+//  public function setSender($sender);
+//
+//  public function getSender();
+
+  public function setRecipient($recipient);
+
+  public function getRecipient();
+
+  public function setEntityTarget($entityTarget);
+
+  public function getEntityTarget();
+
 }

+ 9 - 0
src/StatusTypeInterface.php

@@ -9,4 +9,13 @@ use Drupal\Core\Config\Entity\ConfigEntityInterface;
  */
 interface StatusTypeInterface extends ConfigEntityInterface {
   // Add get/set methods for your configuration properties here.
+
+  public function setMedia($bool);
+
+  public function getMedia();
+
+  public function setMime($mime);
+
+  public function getMime();
+
 }