Passed
Push — v3 ( a18716...001013 )
by Andrew
15:31 queued 07:59
created

PreviewController::actionSocialMedia()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 9
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 19
rs 9.9666
1
<?php
2
/**
3
 * SEOmatic plugin for Craft CMS 3.x
4
 *
5
 * A turnkey SEO implementation for Craft CMS that is comprehensive, powerful,
6
 * and flexible
7
 *
8
 * @link      https://nystudio107.com
9
 * @copyright Copyright (c) 2017 nystudio107
10
 */
11
12
namespace nystudio107\seomatic\controllers;
13
14
use Craft;
15
use craft\base\Element;
16
use craft\elements\Entry;
17
use craft\web\Controller;
18
use nystudio107\seomatic\assetbundles\seomatic\SeomaticAsset;
19
use nystudio107\seomatic\helpers\PluginTemplate;
20
use nystudio107\seomatic\Seomatic;
21
22
/**
23
 * @author    nystudio107
0 ignored issues
show
Coding Style introduced by
The tag in position 1 should be the @package tag
Loading history...
Coding Style introduced by
Content of the @author tag must be in the form "Display Name <[email protected]>"
Loading history...
24
 * @package   Seomatic
25
 * @since     3.2.13
0 ignored issues
show
Coding Style introduced by
The tag in position 3 should be the @author tag
Loading history...
26
 */
27
class PreviewController extends Controller
28
{
29
    // Properties
30
    // =========================================================================
31
32
    /**
33
     * @inheritdoc
34
     */
35
    protected $allowAnonymous = [
36
        'social-media',
37
    ];
38
39
    // Public Methods
40
    // =========================================================================
41
42
    /**
0 ignored issues
show
Coding Style introduced by
Parameter $elementId should have a doc-comment as per coding-style.
Loading history...
Coding Style introduced by
Parameter $siteId should have a doc-comment as per coding-style.
Loading history...
43
     * @param $elementId
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
44
     * @param $siteId
0 ignored issues
show
Coding Style Documentation introduced by
Missing parameter name
Loading history...
45
     *
46
     * @return \yii\web\Response
47
     * @throws \yii\web\BadRequestHttpException
48
     * @throws \yii\base\InvalidConfigException
49
     */
50
    public function actionSocialMedia($elementId, $siteId)
51
    {
52
        $html = '';
53
54
        /** @var Element $element */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
55
        $element = Craft::$app->getElements()->getElementById($elementId, null, $siteId);
56
        if ($element !== null) {
57
            Seomatic::$view->registerAssetBundle(SeomaticAsset::class);
58
            /** @var  $entry Entry */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
59
            if ($element->uri !== null) {
60
                Seomatic::$plugin->metaContainers->previewMetaContainers($element->uri, $element->siteId, true);
61
                // Render our preview sidebar template
62
                if (Seomatic::$matchedElement) {
63
                    $html = PluginTemplate::renderPluginTemplate('_frontend/preview/social-media.twig');
64
                }
65
            }
66
        }
67
68
        return $this->asRaw($html);
69
    }
70
}
71