- 🇮🇳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 10:22am 24 January 2023 - Status changed to Needs work
about 2 years ago 10:58am 24 January 2023 - 🇬🇧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.
- 🇺🇸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 thisthis 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.