|
@@ -2,6 +2,9 @@
|
|
|
|
|
|
namespace Drupal\dr8_zth\Entity;
|
|
namespace Drupal\dr8_zth\Entity;
|
|
|
|
|
|
|
|
+use Drupal\Core\Entity\EntityTypeInterface;
|
|
|
|
+use Drupal\Core\Field\BaseFieldDefinition;
|
|
|
|
+use Drupal\dr8_zth\BlogInterface;
|
|
use Drupal\Core\Entity\ContentEntityBase;
|
|
use Drupal\Core\Entity\ContentEntityBase;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -31,9 +34,14 @@ use Drupal\Core\Entity\ContentEntityBase;
|
|
* "langcode" = "langcode",
|
|
* "langcode" = "langcode",
|
|
* "uuid" = "uuid",
|
|
* "uuid" = "uuid",
|
|
* "status" = "status",
|
|
* "status" = "status",
|
|
- * "author" = "uid",
|
|
|
|
|
|
+ * "uid" = "uid",
|
|
* },
|
|
* },
|
|
* handlers = {
|
|
* handlers = {
|
|
|
|
+ * "form" = {
|
|
|
|
+ * "default" = "Drupal\dr8_zth\Form\BlogForm",
|
|
|
|
+ * "delete" = "Drupal\dr8_zth\Form\BlogDeleteForm"
|
|
|
|
+ * },
|
|
|
|
+ * "list_builder" = "Drupal\dr8_zth\BlogListBuilder",
|
|
* "route_provider" = {
|
|
* "route_provider" = {
|
|
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
|
|
* "html" = "Drupal\Core\Entity\Routing\DefaultHtmlRouteProvider",
|
|
* }
|
|
* }
|
|
@@ -42,8 +50,8 @@ use Drupal\Core\Entity\ContentEntityBase;
|
|
* field_ui_base_route = "entity.blog_type.edit_form",
|
|
* field_ui_base_route = "entity.blog_type.edit_form",
|
|
* permission_granularity = "entity_type",
|
|
* permission_granularity = "entity_type",
|
|
* links = {
|
|
* links = {
|
|
- * "add-form" = "/admin/content/blog/add/{blog_type}",
|
|
|
|
- * "add-page" = "/admin/content/blog/add",
|
|
|
|
|
|
+ * "add-form" = "/blog/add/{blog_type}",
|
|
|
|
+ * "add-page" = "/blog/add",
|
|
* "canonical" = "/blog/{blog}",
|
|
* "canonical" = "/blog/{blog}",
|
|
* "collection" = "/admin/content/blog",
|
|
* "collection" = "/admin/content/blog",
|
|
* "delete-form" = "/blog/{blog}/delete",
|
|
* "delete-form" = "/blog/{blog}/delete",
|
|
@@ -54,6 +62,71 @@ use Drupal\Core\Entity\ContentEntityBase;
|
|
* admin_permission = "administer blog",
|
|
* admin_permission = "administer blog",
|
|
* )
|
|
* )
|
|
*/
|
|
*/
|
|
-class Blog extends ContentEntityBase {
|
|
|
|
|
|
+class Blog extends ContentEntityBase implements BlogInterface {
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @var \Drupal\user\Entity\User
|
|
|
|
+ */
|
|
|
|
+ protected $uid;
|
|
|
|
+
|
|
|
|
+ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
|
|
|
|
+ $fields = parent::baseFieldDefinitions($entity_type);
|
|
|
|
+ $fields['title'] = BaseFieldDefinition::create('string')
|
|
|
|
+ ->setLabel(t('Title'))
|
|
|
|
+ ->setRequired(TRUE)
|
|
|
|
+ ->setTranslatable(TRUE)
|
|
|
|
+ ->setRevisionable(TRUE)
|
|
|
|
+ ->setSetting('max_length', 255)
|
|
|
|
+ ->setDisplayOptions('view', array(
|
|
|
|
+ 'label' => 'hidden',
|
|
|
|
+ 'type' => 'string',
|
|
|
|
+ 'weight' => -5,
|
|
|
|
+ ))
|
|
|
|
+ ->setDisplayOptions('form', array(
|
|
|
|
+ 'type' => 'string_textfield',
|
|
|
|
+ 'weight' => -5,
|
|
|
|
+ ))
|
|
|
|
+ ->setDisplayConfigurable('form', TRUE);
|
|
|
|
+
|
|
|
|
+ $fields['uid'] = BaseFieldDefinition::create('entity_reference')
|
|
|
|
+ ->setLabel(t('Authored by'))
|
|
|
|
+ ->setDescription(t('The username of the blog author.'))
|
|
|
|
+ ->setRevisionable(TRUE)
|
|
|
|
+ ->setSetting('target_type', 'user')
|
|
|
|
+ ->setDefaultValueCallback('Drupal\node\Entity\Node::getCurrentUserId')
|
|
|
|
+ ->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',
|
|
|
|
+ 'placeholder' => '',
|
|
|
|
+ ),
|
|
|
|
+ ))
|
|
|
|
+ ->setDisplayConfigurable('form', TRUE);
|
|
|
|
+
|
|
|
|
+ ksm($fields);
|
|
|
|
+ return $fields;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return \Drupal\user\Entity\User
|
|
|
|
+ */
|
|
|
|
+ public function getAuthor() {
|
|
|
|
+ return $this->get('uid')->entity;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * {@inheritdoc}
|
|
|
|
+ */
|
|
|
|
+ public function getAuthorId() {
|
|
|
|
+ return $this->getEntityKey('uid');
|
|
|
|
+ }
|
|
|
|
|
|
}
|
|
}
|