1 | <?php |
||
43 | class TwitterEmbedTweetBlockService extends BaseTwitterButtonBlockService implements EditableBlockService |
||
44 | { |
||
45 | public const TWITTER_OEMBED_URI = 'https://api.twitter.com/1/statuses/oembed.json'; |
||
46 | private const TWEET_URL_PATTERN = '%^(https://)(www.)?(twitter.com/)(.*)(/status)(es)?(/)([0-9]*)$%i'; |
||
47 | private const TWEET_ID_PATTERN = '%^([0-9]*)$%'; |
||
48 | |||
49 | /** |
||
50 | * @var ClientInterface|null |
||
51 | */ |
||
52 | private $httpClient; |
||
53 | |||
54 | /** |
||
55 | * @var RequestFactoryInterface|null |
||
56 | */ |
||
57 | private $messageFactory; |
||
58 | |||
59 | public function __construct( |
||
60 | Environment $twig, |
||
61 | ClientInterface $httpClient = null, |
||
62 | RequestFactoryInterface $messageFactory = null |
||
63 | ) { |
||
64 | parent::__construct($twig); |
||
65 | |||
66 | $this->httpClient = $httpClient; |
||
67 | $this->messageFactory = $messageFactory; |
||
68 | } |
||
69 | |||
70 | public function execute(BlockContextInterface $blockContext, Response $response = null): Response |
||
71 | { |
||
72 | return $this->renderResponse($blockContext->getTemplate(), [ |
||
73 | 'block' => $blockContext->getBlock(), |
||
74 | 'tweet' => $this->loadTweet($blockContext), |
||
75 | ], $response); |
||
76 | } |
||
77 | |||
78 | public function configureSettings(OptionsResolver $resolver): void |
||
92 | |||
93 | public function configureCreateForm(FormMapper $form, BlockInterface $block): void |
||
94 | { |
||
95 | $this->configureEditForm($form, $block); |
||
96 | } |
||
97 | |||
98 | public function configureEditForm(FormMapper $form, BlockInterface $block): void |
||
99 | { |
||
100 | $form->add('settings', ImmutableArrayType::class, [ |
||
101 | 'keys' => [ |
||
102 | ['tweet', TextareaType::class, [ |
||
103 | 'required' => true, |
||
104 | 'label' => 'form.label_tweet', |
||
105 | 'sonata_help' => 'form.help_tweet', |
||
106 | ]], |
||
107 | ['maxwidth', IntegerType::class, [ |
||
108 | 'required' => false, |
||
109 | 'label' => 'form.label_maxwidth', |
||
110 | 'sonata_help' => 'form.help_maxwidth', |
||
111 | ]], |
||
112 | ['hide_media', CheckboxType::class, [ |
||
113 | 'required' => false, |
||
114 | 'label' => 'form.label_hide_media', |
||
115 | 'sonata_help' => 'form.help_hide_media', |
||
116 | ]], |
||
117 | ['hide_thread', CheckboxType::class, [ |
||
118 | 'required' => false, |
||
119 | 'label' => 'form.label_hide_thread', |
||
120 | 'sonata_help' => 'form.help_hide_thread', |
||
121 | ]], |
||
122 | ['omit_script', CheckboxType::class, [ |
||
123 | 'required' => false, |
||
124 | 'label' => 'form.label_omit_script', |
||
125 | 'sonata_help' => 'form.help_omit_script', |
||
126 | ]], |
||
127 | ['align', ChoiceType::class, [ |
||
128 | 'required' => false, |
||
129 | 'choices' => [ |
||
130 | 'left' => 'form.label_align_left', |
||
131 | 'right' => 'form.label_align_right', |
||
132 | 'center' => 'form.label_align_center', |
||
133 | 'none' => 'form.label_align_none', |
||
134 | ], |
||
135 | 'label' => 'form.label_align', |
||
136 | ]], |
||
137 | ['related', TextType::class, [ |
||
138 | 'required' => false, |
||
139 | 'label' => 'form.label_related', |
||
140 | 'sonata_help' => 'form.help_related', |
||
141 | ]], |
||
142 | ['lang', ChoiceType::class, [ |
||
143 | 'required' => true, |
||
144 | 'choices' => $this->languageList, |
||
145 | 'label' => 'form.label_lang', |
||
146 | ]], |
||
147 | ], |
||
148 | 'translation_domain' => 'SonataSeoBundle', |
||
149 | ]); |
||
150 | } |
||
151 | |||
152 | public function validate(ErrorElement $errorElement, BlockInterface $block): void |
||
153 | { |
||
154 | } |
||
155 | |||
156 | public function getMetadata(): MetadataInterface |
||
157 | { |
||
158 | return new \Sonata\BlockBundle\Meta\Metadata('sonata.seo.block.twitter.embed', null, null, 'SonataSeoBundle', [ |
||
159 | 'class' => 'fa fa-twitter', |
||
160 | ]); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * Returns supported API parameters from settings. |
||
165 | * |
||
166 | * @return array |
||
167 | */ |
||
168 | protected function getSupportedApiParams() |
||
169 | { |
||
170 | return [ |
||
171 | 'maxwidth', |
||
172 | 'hide_media', |
||
173 | 'hide_thread', |
||
174 | 'omit_script', |
||
175 | 'align', |
||
176 | 'related', |
||
177 | 'lang', |
||
178 | 'url', |
||
179 | 'id', |
||
180 | ]; |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * Builds the API query URI based on $settings. |
||
185 | * |
||
186 | * @param bool $uriMatched |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | protected function buildUri($uriMatched, array $settings) |
||
213 | |||
214 | /** |
||
215 | * Loads twitter tweet. |
||
216 | */ |
||
217 | private function loadTweet(BlockContextInterface $blockContext): ?string |
||
273 | } |
||
274 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: