width = $width; // Height. $this->height = $height; // Grid Width. $this->gridWidth = $gridWidth; // Options. $this->values = $this->decoders($this->getOptionsWidget()); // Positions. $this->position = $this->getPositionWidget(); // Page. $this->page = basename(__FILE__); // ClassName. $class = new \ReflectionClass($this); $this->className = $class->getShortName(); // Title. $this->title = __('URL content'); // Name. if (empty($this->name) === true) { $this->name = 'url'; } // This forces at least a first configuration. $this->configurationRequired = false; if (empty($this->values['urlText']) === true) { $this->configurationRequired = true; } $this->overflow_scrollbars = false; } /** * Decoders hack for retrocompability. * * @param array $decoder Values. * * @return array Returns the values ​​with the correct key. */ public function decoders(array $decoder): array { $values = []; // Retrieve global - common inputs. $values = parent::decoders($decoder); if (isset($decoder['url']) === true) { $values['urlText'] = $decoder['url']; } if (isset($decoder['urlText']) === true) { $values['urlText'] = $decoder['urlText']; } return $values; } /** * Generates inputs for form (specific). * * @return array Of inputs. * * @throws Exception On error. */ public function getFormInputs(): array { $values = $this->values; // Retrieve global - common inputs. $inputs = parent::getFormInputs(); // Url. $inputs[] = [ 'label' => __('Url'), 'arguments' => [ 'name' => 'urlText', 'type' => 'text', 'value' => $values['urlText'], 'return' => true, 'size' => 0, ], ]; return $inputs; } /** * Get Post for widget. * * @return array */ public function getPost():array { // Retrieve global - common inputs. $values = parent::getPost(); $values['urlText'] = \get_parameter('urlText', ''); return $values; } /** * Draw widget. * * @return string; */ public function load() { $output = ''; $url = $this->values['urlText']; $size = parent::getSize(); $width = $size['width']; $height = $size['height']; if (isset($url) === false || empty($url) === true) { $output .= __('Please, configure this widget before use'); } else { if (!preg_match('/^https?:\/\/.+/', $url)) { $url = 'http://'.$url; } $url = str_replace('watch?v=', 'embed/', $url); $style = 'border:none; width:100%; height:'.$height.'px;'; $output .= ''; } return $output; } /** * Get description. * * @return string. */ public static function getDescription() { return __('URL content'); } /** * Get Name. * * @return string. */ public static function getName() { return 'url'; } /** * Get size Modal Configuration. * * @return array */ public function getSizeModalConfiguration(): array { $size = [ 'width' => 450, 'height' => 270, ]; return $size; } }