PHP code example of manta_ray_media / random_hero_bg
1. Go to this page and download the library: Download manta_ray_media/random_hero_bg library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
manta_ray_media / random_hero_bg example snippets
public function clearCache()
{
\Drupal::service('page_cache_kill_switch')->trigger();
\Drupal::service('cache.render')->invalidateAll();
// clear caches for anonymous
Cache::invalidateTags(['HIT']);
}
public function randomBackground(array $input, $number)
{
$this->clearCache();
$key = array_rand($input);
return $input[$key];
}