1<?php
2
3namespace ComboStrap\Meta\Field;
4
5use ComboStrap\MarkupPath;
6use ComboStrap\Meta\Api\Metadata;
7use ComboStrap\Meta\Api\MetadataImage;
8use ComboStrap\Meta\Api\MetadataWikiPath;
9use ComboStrap\PageImageUsage;
10use ComboStrap\SiteConfig;
11use ComboStrap\WikiPath;
12
13
14class FacebookImage extends MetadataImage
15{
16
17
18    const PROPERTY_NAME = "facebook-image";
19
20
21    public static function createFromResource(MarkupPath $page)
22    {
23        return (new FacebookImage())->setResource($page);
24    }
25
26    static public function getDescription(): string
27    {
28        return "The Facebook/OpenGraph image used in Facebook and OpenGraph card (Signal, ...)";
29    }
30
31    static public function getLabel(): string
32    {
33        return "Facebook/OpenGraph";
34    }
35
36    public static function getName(): string
37    {
38        return self::PROPERTY_NAME;
39    }
40
41    static public function getPersistenceType(): string
42    {
43        return Metadata::PERSISTENT_METADATA;
44    }
45
46    static public function isMutable(): bool
47    {
48        return true;
49    }
50
51    public function setFromStoreValueWithoutException($value): Metadata
52    {
53
54        if ($value === null) {
55            $pageImages = PageImages::createForPage($this->getResource())
56                ->setReadStore($this->getReadStore())
57                ->getValueAsPageImages();
58            foreach ($pageImages as $pageImage) {
59                if (in_array(PageImageUsage::FACEBOOK, $pageImage->getUsages())) {
60                    return parent::setFromStoreValueWithoutException($pageImage->getImagePath()->toAbsoluteId());
61                }
62            }
63        }
64        return parent::setFromStoreValueWithoutException($value);
65
66    }
67
68
69    public function getDefaultValue()
70    {
71
72        return SocialCardImage::createFromResourcePage($this->getResource())
73            ->getValueOrDefault();
74
75    }
76
77    static public function getDrive(): string
78    {
79        return WikiPath::MEDIA_DRIVE;
80    }
81
82    static public function isOnForm(): bool
83    {
84        return true;
85    }
86
87    public static function getCanonical(): string
88    {
89        return "facebook";
90    }
91
92
93}
94