0

I have created a content entity form. Below is the code attached:

/**
 * Defines the mymodule entity.
 *
 * @ingroup mymodule
 *
 * @ContentEntityType(
 *   id = "mymodule",
 *   label = @Translation("mymodule"),
 *   handlers = {
 *     "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
 *     "list_builder" = "Drupal\mymodule\Entity\Controller\mymoduleListBuilder",
 *     "views_data" = "Drupal\views\EntityViewsData",
 *     "form" = {
 *       "default" = "Drupal\mymodule\Form\mymoduleForm",
 *       "edit" = "Drupal\mymodule\Form\mymoduleForm",
 *       "delete" = "Drupal\mymodule\Form\mymoduleDeleteForm",
 *       },
 *      "access" = "Drupal\mymodule\RssFeedsAccessControlHandler",
 *     
 *   },
 *   links = {
 *     "canonical" = "/admin/config/search/mymodule/edit/{mymodule}",
 *     "edit-form" = "/admin/config/search/mymodule/edit/{mymodule}",
 *     "delete-form" = "/admin/config/search/mymodule/delete/{mymodule}",
 *    
 *   },
 *   base_table = "mymodule",
 *   admin_permission = "administer mymodule entity",
 *   fieldable = TRUE,
 *   entity_keys = {
 *     "id" = "id",
 *     "label" = "name",
 *     "uuid" = "uuid",
 *   },
 * )
 */

Here is my class with database table and form fields:

class Myclass extends ContentEntityBase  implements  ContentEntityInterface  {
    public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
        $options_first = node_type_get_names();
        $fields['id'] = BaseFieldDefinition::create('integer')
                ->setLabel(t('ID'))
                ->setDescription(t('The ID of the contact entity'))
                ->setReadOnly(TRUE);
        $fields['uuid'] = BaseFieldDefinition::create('uuid')
                ->setLabel(t('UUID'))
                ->setDescription(t('The UUID of the contact entity'))
                ->setReadOnly(TRUE);
        $fields['name'] = BaseFieldDefinition::create('string')
                ->setLabel(t('Configuration Name'))
                ->setDescription(t('The Configuration Name of the rss entity.'))
                ->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);
        $fields['content_type'] = BaseFieldDefinition::create('list_string')
                ->setLabel(t('Content Type'))
                ->setDescription(t('The Content Type of the Rss entity.'))
                ->setSettings(array(
                  'allowed_values' => $options_first,
                ))
                ->setDisplayOptions('view', array(
                  'label' => 'above',
                  'type' => 'string',
                  'weight' => -4,
                ))
                ->setDisplayOptions('form', array(
                  'type' => 'options_select',
                  'weight' => -4,
                ))
                ->setDisplayConfigurable('form', TRUE)
                ->setDisplayConfigurable('view', TRUE);
        $fields['langcode'] = BaseFieldDefinition::create('language')
                ->setLabel(t('Language code'))
                ->setDescription(t('The language code of Rss entity.'));
        $fields['created'] = BaseFieldDefinition::create('created')
                ->setLabel(t('Created'))
                ->setDescription(t('The time that the entity was created.'));
        $fields['changed'] = BaseFieldDefinition::create('changed')
                ->setLabel(t('Changed'))
                ->setDescription(t('The time that the entity was last edited.'));

        return $fields;

    }
}

My Routing.yml links are:

mymodule.add:
  path: '/admin/config/search/mymodule/add'
  defaults:
    _entity_form: 'mymodule.default'
    _title: 'Add form'
  requirements:
    _entity_create_access: 'mymodule'

entity.mymodule.edit_form:
  path: '/admin/config/search/mymodule/edit/{mymodule}'
  defaults:
    _entity_form: 'mymodule.edit'
    _title: 'Edit form'
  requirements:
    _entity_access: 'mymodule.edit'

Form gets created and values are submitted in database, which is fine. But when I click on edit link, form doesn't get open, instead only content type selected value get shown. Why I'm not able to edit/update form? Any suggestion where and what is being missed in creating content type entity form?

  • Try to remove the canonical link – Eyal Jun 14 '16 at 15:33
-1

The links should be different for canonical and edit:

 *     "canonical" = "/admin/config/search/mymodule/edit/{mymodule}",
 *     "edit-form" = "/admin/config/search/mymodule/edit/{mymodule}",

eg

 *     "canonical" = "/admin/config/search/mymodule/{mymodule}",
 *     "edit-form" = "/admin/config/search/mymodule/edit/{mymodule}",
  • Canonical and edit-form url can be same. canonical means default url. I'm setting default url to edit-form url.. – Sugandh Khanna Jun 14 '16 at 10:08
  • What exactly do you get clicking on the edit link? An error, the entity view, a wrong form? – Maouna Jun 14 '16 at 10:36
  • there are two fields in form, one is configuration name, other is select list of content type. I give config name "xyz"(say) and choose content type "article" and hit save. but when I click on edit link from table operations, it shows "article" written on whole page. No Form, No error just "article". – Sugandh Khanna Jun 14 '16 at 12:32
  • It looks like you go to the view of your entity instead of its form. Your routes are not correct defined, but from your code I cannot see where. – Maouna Jun 14 '16 at 19:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.