How can we access the new form modes?

Created on 9 July 2015, over 9 years ago
Updated 10 August 2023, over 1 year ago

I created a simple content type and a form mode for this content type. Where can I view this form mode after creating it? I see no option for form modes when creating a content type. I would have expected an option to be presented when clicking on "Add Content" to select "Add xy content with xy form mode"?

Perhaps with a simple get var like
add/page/?form=light
add/page/?form=heavy

Feature request
Status

Needs work

Version

11.0 🔥

Component
Form 

Last updated 26 minutes ago

Created by

🇭🇺Hungary giorgio79

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • Needs change record

    A change record needs to be drafted before an issue is committed. Note: Change records used to be called change notifications.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India pooja saraah Chennai

    Fixed failed commands on #43
    Attached patch against Drupal 10.1.x
    Attached reroll patch

  • 🇮🇳India prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    Fixed The Custom CMD Failed Patch Of #57

  • Status changed to Needs review about 2 years ago
  • 🇮🇳India prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan
  • Status changed to Needs work about 2 years ago
  • 🇬🇧United Kingdom joachim
    +++ b/core/lib/Drupal/Core/Entity/EntityTypeManager.php
    @@ -202,9 +202,12 @@ public function getListBuilder($entity_type_id) {
    +  public function getFormObject($entity_type, $operation, $form_class = NULL) {
    

    New parameters on both functions need to be documented!!!!!!!

    Also, why change the name of $entity_type_id?

  • 🇮🇳India prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    Reroll the Patch as per Suggestion of #60.

  • 🇮🇳India prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan
  • 🇺🇸United States smustgrave

    @Prem Suthar please read the comments and tags.

    This was tagged for IS update and a change record and question in #60

    Also upload an interdiff with patches please

  • 🇨🇦Canada earthangelconsulting

    i just want to add some confirmation, for the benefit of those who have found this page while trying to use form modes from custom code (rather than anything to do with actual code changes to Core)

    those modules form_mode_control and form_mode_manager may be very handy, but if you are just trying to generate a node form from php, with an alternate (but already defined) form mode for that node type, then ALL you need is what is mentioned in #13 ! thanks, @dench0 that was very helpful!

    i tried this in Drupal 9.4.15 and it still works just fine :-)

  • 🇪🇸Spain ady1503

    @earthangelconsulting

    Can you show an real example?

    Where did did you implement the code.

    Thanks

    Gracias

  • 🇨🇦Canada earthangelconsulting

    foo_posting is the machine name of a node type
    foo_specialform is the machine name of a custom form mode, for nodes of type foo_posting
    foomodule is the module that handles this

    this is in the src/FooController.php script, within foomodule: (note that this use case is for a path that calls a node/add form, using form mode foo_posting ... if you need to edit existing nodes, it would be a bit different)

    namespace Drupal\foomodule\Controller;
    
    use Drupal\Core\Controller\ControllerBase;
    use Drupal\node\Entity\Node;
    
    class FooController extends ControllerBase {
    
      /**
       * Function to call the Foo Posting form
       *
       * @return array
       *   A renderable array
       */
      public function postFoo() {
      
        $node = Node::create(array(
        'type' => 'foo_posting',
        ));
    	
        $form = \Drupal::service('entity.form_builder')->getForm($node, 'foo_specialform');  
        
        return [
          'form' => $form
        ];
      }
    
    }

    this is in foomodule.routing.yml (nothing out of the ordinary here! )

    foomodule.fooposting:
      path: '/foo-posting'
      defaults:
        _controller: 'Drupal\foomodule\Controller\FooController::postFoo'
        _title: 'Post an instance of Foo'
      requirements:
        _access: 'TRUE'
    

    and this is part of foomodule.module

    function foomodule_entity_type_build(array &$entity_types) {
      $entity_types['node']->setFormClass('foo_specialform', 'Drupal\node\NodeForm');
    }
    

    there are definitely other ways to do this, eg: https://www.webomelette.com/how-switch-out-entity-form-mode-dynamically-... https://www.drupal.org/docs/drupal-apis/entity-api/how-to-create-an-enti... this is just one of them.

  • 🇪🇸Spain ady1503

    @earthangelconsulting

    Thank you so much.

    Gracias

Production build 0.71.5 2024