-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathGenerateSocialImages.php
More file actions
60 lines (51 loc) · 1.82 KB
/
GenerateSocialImages.php
File metadata and controls
60 lines (51 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<?php
namespace Studio1902\PeakSeo\Actions;
use Statamic\Actions\Action;
use Statamic\Contracts\Entries\Entry as EntryInstance;
use Statamic\Globals\GlobalSet;
use Studio1902\PeakSeo\Jobs\GenerateSocialImagesJob;
class GenerateSocialImages extends Action
{
public $available_collections = array();
public $icon = 'share-mega-phone';
public function __construct() {
if (GlobalSet::findByHandle('seo')->inDefaultSite()->get('use_social_image_generation') && GlobalSet::findByHandle('seo')->inDefaultSite()->get('social_images_collections')) {
$this->available_collections = GlobalSet::findByHandle('seo')->inDefaultSite()->get('social_images_collections');
}
}
/**
* Determine if the current thing is an entry and if it's opted in to the auto generation config (global).
*
* @return boolean
*/
public function visibleTo($item)
{
return $item instanceof EntryInstance && in_array($item->collectionHandle(), $this->available_collections);
}
/**
* Determine if the current user is allowed to run this action.
*
* @return boolean
*/
public function authorize($user, $item)
{
return $user->can('edit', $item);
}
/**
* Run the action
*
* @return void
*/
public function run($items, $values)
{
$items->each(function ($item, $key) {
GenerateSocialImagesJob::dispatch($item)
->onQueue(config('statamic-peak-seo.social_image.queue_name'));
});
$queue = config('queue.default');
$driver = config("queue.connections.$queue.driver");
return $driver === 'sync'
? trans_choice('statamic-peak-seo::default.social_images', $items)
: trans_choice('statamic-peak-seo::default.social_images_queue', $items);
}
}