diff --git a/content_entity_example/content_entity_example.local_actions.yml b/content_entity_example/content_entity_example.local_actions.yml index 6f8773c..f181615 100755 --- a/content_entity_example/content_entity_example.local_actions.yml +++ b/content_entity_example/content_entity_example.local_actions.yml @@ -4,4 +4,3 @@ content_entity_example.add: appears_on: - content_entity_example.list - content_entity_example.view - \ No newline at end of file diff --git a/content_entity_example/lib/Drupal/content_entity_example/ContentEntityExampleInterface.php b/content_entity_example/lib/Drupal/content_entity_example/ContentEntityExampleInterface.php deleted file mode 100755 index 4ce6bc7..0000000 --- a/content_entity_example/lib/Drupal/content_entity_example/ContentEntityExampleInterface.php +++ /dev/null @@ -1,17 +0,0 @@ - \Drupal::currentUser()->id(), - ); - } - - /** - * {@inheritdoc} - */ - public function getCreatedTime() { - return $this->get('created')->value; - } - - /** - * {@inheritdoc} - */ - public function getChangedTime() { - return $this->get('changed')->value; - } - - /** - * {@inheritdoc} - */ - public function getOwner() { - return $this->get('user_id')->entity; - } - - /** - * {@inheritdoc} - */ - public function getOwnerId() { - return $this->get('user_id')->target_id; - } - - /** - * {@inheritdoc} - */ - public function setOwnerId($uid) { - $this->set('user_id', $uid); - return $this; - } - - /** - * {@inheritdoc} - */ - public function setOwner(UserInterface $account) { - $this->set('user_id', $account->id()); - return $this; - } - - /** - * {@inheritdoc} - */ - public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { - $fields['id'] = FieldDefinition::create('integer') - ->setLabel(t('ID')) - ->setDescription(t('The ID of the ContentEntityExample entity.')) - ->setReadOnly(TRUE); - - $fields['uuid'] = FieldDefinition::create('uuid') - ->setLabel(t('UUID')) - ->setDescription(t('The UUID of the ContentEntityExample entity.')) - ->setReadOnly(TRUE); - - $fields['name'] = FieldDefinition::create('string') - ->setLabel(t('Name')) - ->setDescription(t('The name of the ContentEntityExample entity.')) - ->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['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.')); - - $fields['changed'] = FieldDefinition::create('changed') - ->setLabel(t('Changed')) - ->setDescription(t('The time that the entity was last edited.')); - - return $fields; - } -} diff --git a/content_entity_example/lib/Drupal/content_entity_example/Entity/Controller/ContentEntityExampleListController.php b/content_entity_example/lib/Drupal/content_entity_example/Entity/Controller/ContentEntityExampleListController.php deleted file mode 100755 index 18be0da..0000000 --- a/content_entity_example/lib/Drupal/content_entity_example/Entity/Controller/ContentEntityExampleListController.php +++ /dev/null @@ -1,41 +0,0 @@ -id(); - $row['label'] = \Drupal::l($this->getLabel($entity), - 'content_entity_example.view', array( - 'content_entity_example' => $entity->id(), - )); - return $row + parent::buildRow($entity); - } -} diff --git a/content_entity_example/lib/Drupal/content_entity_example/Entity/Form/ContentEntityExampleDeleteForm.php b/content_entity_example/lib/Drupal/content_entity_example/Entity/Form/ContentEntityExampleDeleteForm.php deleted file mode 100755 index 1e52626..0000000 --- a/content_entity_example/lib/Drupal/content_entity_example/Entity/Form/ContentEntityExampleDeleteForm.php +++ /dev/null @@ -1,53 +0,0 @@ - $this->entity->label())); - } - - /** - * {@inheritdoc} - */ - public function getCancelRoute() { - return array( - 'route_name' => 'content_entity_example.list', - ); - } - - /** - * {@inheritdoc} - */ - public function getConfirmText() { - return t('Delete'); - } - - /** - * {@inheritdoc} - */ - public function submit(array $form, array &$form_state) { - $this->entity->delete(); - - watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label())); - $form_state['redirect_route']['route_name'] = 'content_entity_example.list'; - } - -} 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 deleted file mode 100755 index 3a448ba..0000000 --- a/content_entity_example/lib/Drupal/content_entity_example/Entity/Form/ContentEntityExampleFormController.php +++ /dev/null @@ -1,65 +0,0 @@ -entity; - - $form['user_id'] = array( - '#type' => 'textfield', - '#title' => 'UID', - '#default_value' => $entity->user_id->target_id, - '#size' => 60, - '#maxlength' => 128, - '#required' => TRUE, - '#weight' => -10, - ); - - $form['langcode'] = array( - '#title' => t('Language'), - '#type' => 'language_select', - '#default_value' => $entity->getUntranslated()->language()->id, - '#languages' => Language::STATE_ALL, - ); - - return $form; - } - - /** - * Overrides \Drupal\Core\Entity\EntityFormController::submit(). - */ - public function submit(array $form, array &$form_state) { - // Build the entity object from the submitted values. - $entity = parent::submit($form, $form_state); - $form_state['redirect_route']['route_name'] = 'content_entity_example.list'; - - return $entity; - } - - /** - * Overrides Drupal\Core\Entity\EntityFormController::save(). - */ - public function save(array $form, array &$form_state) { - $entity = $this->entity; - $entity->save(); - } -} diff --git a/content_entity_example/lib/Drupal/content_entity_example/Form/ContentEntityExampleSettingsForm.php b/content_entity_example/lib/Drupal/content_entity_example/Form/ContentEntityExampleSettingsForm.php deleted file mode 100755 index 51b4e2e..0000000 --- a/content_entity_example/lib/Drupal/content_entity_example/Form/ContentEntityExampleSettingsForm.php +++ /dev/null @@ -1,54 +0,0 @@ - 'Content Entity Example tests', - 'description' => 'Tests the basic functions of the Content Entity Example module.', - 'group' => 'Content Entity Example', - ); - } - - public function setUp() { - parent::setUp(); - - $this->web_user = $this->drupalCreateUser(array('view content_entity_example entity')); - $this->drupalPlaceBlock('system_menu_block:tools', array()); - } - - /** - * Basic tests for Content Entity Example. - */ - public function testContentEntityExample() { - - $this->assertNoText('Content Entity Example Listing'); - - $this->drupalLogin($this->web_user); - - $this->assertLink('Content Entity Example Listing'); - - } -} diff --git a/content_entity_example/src/ContentEntityExampleInterface.php b/content_entity_example/src/ContentEntityExampleInterface.php new file mode 100755 index 0000000..4ce6bc7 --- /dev/null +++ b/content_entity_example/src/ContentEntityExampleInterface.php @@ -0,0 +1,17 @@ + \Drupal::currentUser()->id(), + ); + } + + /** + * {@inheritdoc} + */ + public function getCreatedTime() { + return $this->get('created')->value; + } + + /** + * {@inheritdoc} + */ + public function getChangedTime() { + return $this->get('changed')->value; + } + + /** + * {@inheritdoc} + */ + public function getOwner() { + return $this->get('user_id')->entity; + } + + /** + * {@inheritdoc} + */ + public function getOwnerId() { + return $this->get('user_id')->target_id; + } + + /** + * {@inheritdoc} + */ + public function setOwnerId($uid) { + $this->set('user_id', $uid); + return $this; + } + + /** + * {@inheritdoc} + */ + public function setOwner(UserInterface $account) { + $this->set('user_id', $account->id()); + return $this; + } + + /** + * {@inheritdoc} + */ + public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { + $fields['id'] = FieldDefinition::create('integer') + ->setLabel(t('ID')) + ->setDescription(t('The ID of the ContentEntityExample entity.')) + ->setReadOnly(TRUE); + + $fields['uuid'] = FieldDefinition::create('uuid') + ->setLabel(t('UUID')) + ->setDescription(t('The UUID of the ContentEntityExample entity.')) + ->setReadOnly(TRUE); + + $fields['name'] = FieldDefinition::create('string') + ->setLabel(t('Name')) + ->setDescription(t('The name of the ContentEntityExample entity.')) + ->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['user_id'] = FieldDefinition::create('entity_reference') + ->setLabel(t('User ID')) + ->setDescription(t('The ID of the associated user.')) + ->setSetting('target_type', 'user') + ->setSetting('handler', 'default') + ->setDisplayOptions('view', array( + 'label' => 'above', + 'type' => 'entity_reference', + 'weight' => -6, + )) + ->setDisplayOptions('form', array( + 'type' => 'entity_reference_autocomplete', + 'settings' => array( + 'match_operator' => 'CONTAINS', + 'size' => 60, + 'autocomplete_type' => 'tags', + 'placeholder' => '', + ), + 'weight' => -6, + )) + ->setDisplayConfigurable('form', TRUE) + ->setDisplayConfigurable('view', TRUE); + + + $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.')); + + $fields['changed'] = FieldDefinition::create('changed') + ->setLabel(t('Changed')) + ->setDescription(t('The time that the entity was last edited.')); + + return $fields; + } +} diff --git a/content_entity_example/src/Entity/Controller/ContentEntityExampleListController.php b/content_entity_example/src/Entity/Controller/ContentEntityExampleListController.php new file mode 100755 index 0000000..18be0da --- /dev/null +++ b/content_entity_example/src/Entity/Controller/ContentEntityExampleListController.php @@ -0,0 +1,41 @@ +id(); + $row['label'] = \Drupal::l($this->getLabel($entity), + 'content_entity_example.view', array( + 'content_entity_example' => $entity->id(), + )); + return $row + parent::buildRow($entity); + } +} diff --git a/content_entity_example/src/Entity/Form/ContentEntityExampleDeleteForm.php b/content_entity_example/src/Entity/Form/ContentEntityExampleDeleteForm.php new file mode 100755 index 0000000..1e52626 --- /dev/null +++ b/content_entity_example/src/Entity/Form/ContentEntityExampleDeleteForm.php @@ -0,0 +1,53 @@ + $this->entity->label())); + } + + /** + * {@inheritdoc} + */ + public function getCancelRoute() { + return array( + 'route_name' => 'content_entity_example.list', + ); + } + + /** + * {@inheritdoc} + */ + public function getConfirmText() { + return t('Delete'); + } + + /** + * {@inheritdoc} + */ + public function submit(array $form, array &$form_state) { + $this->entity->delete(); + + watchdog('content', '@type: deleted %title.', array('@type' => $this->entity->bundle(), '%title' => $this->entity->label())); + $form_state['redirect_route']['route_name'] = 'content_entity_example.list'; + } + +} diff --git a/content_entity_example/src/Entity/Form/ContentEntityExampleForm.php b/content_entity_example/src/Entity/Form/ContentEntityExampleForm.php new file mode 100755 index 0000000..d91d49a --- /dev/null +++ b/content_entity_example/src/Entity/Form/ContentEntityExampleForm.php @@ -0,0 +1,65 @@ +entity; + + /* $form['user_id'] = array( + '#type' => 'textfield', + '#title' => 'UID', + '#default_value' => $entity->user_id->target_id, + '#size' => 60, + '#maxlength' => 128, + '#required' => TRUE, + '#weight' => -10, + );*/ + + $form['langcode'] = array( + '#title' => t('Language'), + '#type' => 'language_select', + '#default_value' => $entity->getUntranslated()->language()->id, + '#languages' => Language::STATE_ALL, + ); + + return $form; + } + + /** + * Overrides \Drupal\Core\Entity\EntityFormController::submit(). + */ + public function submit(array $form, array &$form_state) { + // Build the entity object from the submitted values. + $entity = parent::submit($form, $form_state); + $form_state['redirect_route']['route_name'] = 'content_entity_example.list'; + + return $entity; + } + + /** + * Overrides Drupal\Core\Entity\EntityFormController::save(). + */ + public function save(array $form, array &$form_state) { + $entity = $this->entity; + $entity->save(); + } +} diff --git a/content_entity_example/src/Form/ContentEntityExampleSettingsForm.php b/content_entity_example/src/Form/ContentEntityExampleSettingsForm.php new file mode 100755 index 0000000..51b4e2e --- /dev/null +++ b/content_entity_example/src/Form/ContentEntityExampleSettingsForm.php @@ -0,0 +1,54 @@ + 'Content Entity Example tests', + 'description' => 'Tests the basic functions of the Content Entity Example module.', + 'group' => 'Content Entity Example', + ); + } + + public function setUp() { + parent::setUp(); + + $this->web_user = $this->drupalCreateUser(array('view content_entity_example entity')); + $this->drupalPlaceBlock('system_menu_block:tools', array()); + } + + /** + * Basic tests for Content Entity Example. + */ + public function testContentEntityExample() { + + $this->assertNoText('Content Entity Example Listing'); + + $this->drupalLogin($this->web_user); + + $this->assertLink('Content Entity Example Listing'); + + } +}