diff --git a/content_entity_example/content_entity_example.install b/content_entity_example/content_entity_example.install index caf01d4..c32cbf2 100755 --- a/content_entity_example/content_entity_example.install +++ b/content_entity_example/content_entity_example.install @@ -29,13 +29,20 @@ function content_entity_example_schema() { 'not null' => TRUE, 'default' => '', ), - 'uid' => array( + 'user_id' => array( 'type' => 'int', 'unsigned' => TRUE, 'not null' => FALSE, 'default' => NULL, 'description' => 'The {users}.uid of the associated user.', ), + 'langcode' => array( + 'description' => 'The {language}.langcode of the original variant of this ContentEntityExample entity.', + 'type' => 'varchar', + 'length' => 12, + 'not null' => TRUE, + 'default' => '', + ), 'created' => array( 'description' => 'The Unix timestamp when the entity was created.', 'type' => 'int', diff --git a/content_entity_example/content_entity_example.local_actions.yml b/content_entity_example/content_entity_example.local_actions.yml index 19e1af8..f181615 100755 --- a/content_entity_example/content_entity_example.local_actions.yml +++ b/content_entity_example/content_entity_example.local_actions.yml @@ -2,4 +2,5 @@ content_entity_example.add: route_name: content_entity_example.add title: 'Add Content Entity Example Content' appears_on: - - content_entity_example.list \ No newline at end of file + - content_entity_example.list + - content_entity_example.view diff --git a/content_entity_example/lib/Drupal/content_entity_example/Entity/ContentEntityExample.php b/content_entity_example/lib/Drupal/content_entity_example/Entity/ContentEntityExample.php index e400654..e6a8cfe 100755 --- a/content_entity_example/lib/Drupal/content_entity_example/Entity/ContentEntityExample.php +++ b/content_entity_example/lib/Drupal/content_entity_example/Entity/ContentEntityExample.php @@ -50,7 +50,7 @@ class ContentEntityExample extends ContentEntityBase implements ContentEntityExa public static function preCreate(EntityStorageControllerInterface $storage_controller, array &$values) { parent::preCreate($storage_controller, $values); $values += array( - 'uid' => \Drupal::currentUser()->id(), + 'user_id' => \Drupal::currentUser()->id(), ); } @@ -72,21 +72,21 @@ class ContentEntityExample extends ContentEntityBase implements ContentEntityExa * {@inheritdoc} */ public function getOwner() { - return $this->get('uid')->entity; + return $this->get('user_id')->entity; } /** * {@inheritdoc} */ public function getOwnerId() { - return $this->get('uid')->target_id; + return $this->get('user_id')->target_id; } /** * {@inheritdoc} */ public function setOwnerId($uid) { - $this->set('uid', $uid); + $this->set('user_id', $uid); return $this; } @@ -94,7 +94,7 @@ class ContentEntityExample extends ContentEntityBase implements ContentEntityExa * {@inheritdoc} */ public function setOwner(UserInterface $account) { - $this->set('uid', $account->id()); + $this->set('user_id', $account->id()); return $this; } @@ -132,11 +132,14 @@ class ContentEntityExample extends ContentEntityBase implements ContentEntityExa ->setDisplayConfigurable('form', TRUE) ->setDisplayConfigurable('view', TRUE); - $fields['uid'] = FieldDefinition::create('entity_reference') + $fields['user_id'] = FieldDefinition::create('entity_reference') ->setLabel(t('User ID')) ->setDescription(t('The ID of the associated user.')) ->setSettings(array('target_type' => 'user')); + $fields['langcode'] = FieldDefinition::create('language') + ->setLabel(t('Language code')) + ->setDescription(t('The language code of ContentEntityExample entity.')); $fields['created'] = FieldDefinition::create('created') ->setLabel(t('Created')) ->setDescription(t('The time that the entity was created.')); diff --git a/content_entity_example/lib/Drupal/content_entity_example/Entity/Form/ContentEntityExampleFormController.php b/content_entity_example/lib/Drupal/content_entity_example/Entity/Form/ContentEntityExampleFormController.php index d7b6d86..69eef29 100755 --- a/content_entity_example/lib/Drupal/content_entity_example/Entity/Form/ContentEntityExampleFormController.php +++ b/content_entity_example/lib/Drupal/content_entity_example/Entity/Form/ContentEntityExampleFormController.php @@ -22,10 +22,10 @@ class ContentEntityExampleFormController extends ContentEntityFormController { $form = parent::form($form, $form_state); $entity = $this->entity; - $form['uid'] = array( + $form['user_id'] = array( '#type' => 'textfield', '#title' => 'UID', - '#default_value' => $entity->uid->target_id, + '#default_value' => $entity->user_id->target_id, '#size' => 60, '#maxlength' => 128, '#required' => TRUE,