Attachment third pary ( Youtube etc ... ). Is a sub project of plugin 3xw/attachment
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require 3xw/attachment-third-party
Acrtive the plugin in your Application.php file:
// Queue
$this->addPlugin('Queue');
Then migrate the db
bin/cake migrations migrate -p Queue
Install Google lib:
composer require google/apiclient:^2.0
Ignore your Google private settings. Add following in .gitignore file:
/config/google/*
- select/create a Google project here
- active Youtube Library in library menu
- create and download a OAuth Client (of type "Other"), place it as config/google/credentials.json
When using attachment, setup an event listener either:
- globally in your config/attachment.php
return [
'Attachment' => [
//...
'listeners' => [
'beforeSave' => [
'Attachment\Listener\ModifyTypeListener' => [
'type' => 'transit',
'subtype' => 'youtube', // or other third party name
]
],
]
//...
]
];
- specifically in any template:
$this->Attachment->buildIndex([
'actions' => ['add','edit','delete','view'],
'types' =>['image/jpeg','image/png','embed/youtube','embed/vimeo','video/quicktime','transit/youtube'],
'listeners' => [
'beforeSave' => [
'Attachment\Listener\ModifyTypeListener' => [
'type' => 'transit',
'subtype' => 'youtube',
]
],
]
])
By creating a cron tasks, the plugin will look for attachments with a type "transit" and create Queue tasks for each attachment with relevant Mover Class.
bin/cake queue add CreateTransitStack & bin/cake queue runworker