This is a simple alteration that would allow the Loading... text to be configurable via the render element.

In AjaxPlaceholder.php change the #markup element to get it's value from the render element.

public static function preRender(array $element) {
    // Set the callback data in the tempstore and use a temporary hash to
    // retrieve it.
    $tempstore = \Drupal::service('tempstore.shared')->get('ajax_placeholder');
    $hash = md5(Json::encode($element['#callback']));
    $tempstore->set($hash, [
      'url' => \Drupal::request()->getRequestUri(),
      'callback' => $element['#callback'],
    ]);
    return [
      'container' => [
        '#type' => 'container',
        '#callback' => '',
        '#attributes' => [
          'class' => 'js-ajax-placeholder',
          'data-hash' => $hash,
        ],
        'content' => [
          '#markup' => $element['#markup'] ?: 'Loading...',
        ],
        '#attached' => [
          'library' => ['ajax_placeholder/ajax'],
        ],
      ],
    ];
  }

Then in the render element it can be defined with a custom loading message image.

$build['awesome'] = [
  '#type' => 'ajax_placeholder',
  '#callback' => ['mymodule.service:callback', [$arg1, $arg2]],
  '#markup' => 'My custom loading message ....',
];
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

RustedBucket created an issue. See original summary.

introfini made their first commit to this issue’s fork.

introfini’s picture

Status: Active » Needs review

This way, you can add a custom message or, more interestingly, a spinner or animations.

Please review...

seanb’s picture

Status: Needs review » Fixed

Looks good to me!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.