- Issue created by @RustedBucket
- First commit to issue fork.
- π΅πΉPortugal introfini
This way, you can add a custom message or, more interestingly, a spinner or animations.
Please review...
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 ....',
];
Active
1.0
Code
This way, you can add a custom message or, more interestingly, a spinner or animations.
Please review...