/** * Get a preview of the properties of this widget * @return string */ public function getPropertiesPreview() { $embed = $this->properties->getWidgetProperty(self::PROPERTY_EMBED); $translator = $this->getTranslator(); $preview = ''; $preview .= '<strong>' . $translator->translate('label.template') . '</strong>: ' . $this->getTemplate(static::TEMPLATE_NAMESPACE . '/default') . '<br>'; $preview .= StringHelper::truncate(htmlentities($embed), 120) . '<br>'; return $preview; }
/** * Saves the data in the model * @param mixed $entry * @return nulls */ public function saveEntry($entry) { if (!$this->willSave($entry)) { return; } // generate a name for the text if ($entry->getTitle()) { $entry->name = $entry->getTitle(); } elseif ($entry->getBody()) { $strippedBody = strip_tags($entry->getBody()); if ($strippedBody) { $body = $strippedBody; } else { $body = $entry->getBody(); } $entry->name = StringHelper::truncate($body, 30); } elseif ($entry->getImage()) { $entry->name = $entry->getImage(); } else { $entry->name = 'Text'; } // perform the actual saving return parent::saveEntry($entry); }
/** * Gets a preview for the properties of this widget * @return string */ public function getPropertiesPreview() { $text = $this->getTextIO()->getText($this->properties, $this->locale); $textFormat = $this->getTextFormat($text->getFormat()); $title = $text->getTitle(); $subtitle = $text->getSubtitle(); $body = $textFormat->getHtml($text->getBody()); $image = $text->getImage(); $bodyStripped = trim(strip_tags($body)); if (!$bodyStripped) { $body = htmlentities($body); } else { $body = StringHelper::truncate($bodyStripped, 120); } $translator = $this->getTranslator(); $preview = ''; if ($title) { $preview .= '<strong>' . $translator->translate('label.title') . '</strong>: ' . $title . '<br>'; } if ($subtitle) { $preview .= '<strong>' . $translator->translate('label.subtitle') . '</strong>: ' . $subtitle . '<br>'; } $preview .= '<strong>' . $translator->translate('label.template') . '</strong>: ' . $this->getTemplate(static::TEMPLATE_NAMESPACE . '/' . static::TEMPLATE_DEFAULT) . '<br>'; $preview .= $body; return $preview; }