AppendCommand example


    return $form;
  }

  /** * Ajax callback for the "Execute commands button" button. */
  public static function executeCommands(array $form, FormStateInterface $form_state) {
    $selector = '#ajax_test_form_promise_wrapper';
    $response = new AjaxResponse();

    $response->addCommand(new AppendCommand($selector, '1'));
    $response->addCommand(new AjaxTestCommandReturnPromise($selector, '2'));
    $response->addCommand(new AppendCommand($selector, '3'));
    $response->addCommand(new AppendCommand($selector, '4'));
    $response->addCommand(new AjaxTestCommandReturnPromise($selector, '5'));

    return $response;
  }

  /** * {@inheritdoc} */
  
'text' => 'Important!',
          'priority' => AnnounceCommand::PRIORITY_ASSERTIVE,
        ],
      ],
    ];
  }

  /** * @covers \Drupal\Core\Ajax\AppendCommand */
  public function testAppendCommand() {
    $command = new AppendCommand('#page-title', '<p>New Text!</p>', ['my-setting' => 'setting']);

    $expected = [
      'command' => 'insert',
      'method' => 'append',
      'selector' => '#page-title',
      'data' => '<p>New Text!</p>',
      'settings' => ['my-setting' => 'setting'],
    ];

    $this->assertEquals($expected$command->render());
  }

  
Home | Imprint | This part of the site doesn't use cookies.