/
controller.php
65 lines (56 loc) · 2.23 KB
/
controller.php
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
61
62
63
64
65
<?php
namespace Concrete\Package\OpenGraphTagsLite;
use Concrete\Core\Events\EventDispatcher;
use Concrete\Core\Package\Package;
use Concrete\Core\Page\Single as SinglePage;
use Concrete\Core\Attribute\Key\CollectionKey as CollectionAttributeKey;
use Concrete\Core\Attribute\Type as AttributeType;
use Concrete\Package\OpenGraphTagsLite\Src\Html\OpenGraphTags;
class Controller extends Package
{
protected $pkgHandle = 'open_graph_tags_lite';
protected $appVersionRequired = '9.0.0';
protected $pkgVersion = '3.0.0';
protected $pkgAutoloaderRegistries = [
'src' => '\Concrete\Package\OpenGraphTagsLite\Src',
];
public function getPackageDescription()
{
return t('Auto insert Open Graph Tags (OGP) into HEAD tag');
}
public function getPackageName()
{
return t('Open Graph Tags Lite');
}
public function install()
{
$pkg = parent::install();
//Add dashboard page
$sp = SinglePage::add('/dashboard/open_graph_tags_lite', $pkg);
if (is_object($sp)) {
$sp->update(['cName' => t('Open Graph Tags Lite'), 'cDescription' => t('Auto insert Open Graph Tags (OGP) into HEAD tag')]);
}
$sp = SinglePage::add('/dashboard/open_graph_tags_lite/settings', $pkg);
if (is_object($sp)) {
$sp->update(['cName' => t('Open Graph Tags Settings'), 'cDescription' => '']);
}
//Add og:image attribute
$cak = CollectionAttributeKey::getByHandle('og_image');
if (!is_object($cak)) {
$at = AttributeType::getByHandle('image_file');
$category = $this->app->make('Concrete\Core\Attribute\Category\CategoryService')
->getByHandle('collection');
$category->getController()->add($at, ['akHandle' => 'og_image', 'akName' => t('og:image')], $pkg);
}
return $pkg;
}
public function on_start()
{
$this->app->singleton(OpenGraphTags::class);
/** @var OpenGraphTags $ogp */
$ogp = $this->app->make(OpenGraphTags::class);
/** @var EventDispatcher $dispatcher */
$dispatcher = $this->app->make(EventDispatcher::class);
$dispatcher->addListener('on_before_render', [$ogp, 'insertTags']);
}
}