/** * Stores the text in the data source * @param \ride\library\widget\WidgetProperties $widgetProperties Instance * of the widget properties * @param string|array $locales Code of the current locale * @param \ride\web\cms\text\Text $text Instance of the text * @param array $data Submitted data * @return null */ public function setText(WidgetProperties $widgetProperties, $locales, Text $text, array $data) { if (!is_array($locales)) { $locales = array($locales); } foreach ($locales as $locale) { $widgetProperties->setLocalizedWidgetProperty($locale, TextWidget::PROPERTY_FORMAT, $text->getFormat()); $widgetProperties->setLocalizedWidgetProperty($locale, TextWidget::PROPERTY_TITLE, $data[TextWidget::PROPERTY_TITLE]); $widgetProperties->setLocalizedWidgetProperty($locale, TextWidget::PROPERTY_SUBTITLE, $data[TextWidget::PROPERTY_SUBTITLE]); $widgetProperties->setLocalizedWidgetProperty($locale, TextWidget::PROPERTY_BODY, $data[TextWidget::PROPERTY_BODY]); $widgetProperties->setLocalizedWidgetProperty($locale, str_replace('-', '.', TextWidget::PROPERTY_IMAGE), $data[TextWidget::PROPERTY_IMAGE]); $widgetProperties->setLocalizedWidgetProperty($locale, str_replace('-', '.', TextWidget::PROPERTY_IMAGE_ALIGNMENT), $data[TextWidget::PROPERTY_IMAGE_ALIGNMENT]); $widgetProperties->clearWidgetProperties(TextWidget::PROPERTY_CTA . '.' . $locale); $index = 1; foreach ($data[TextWidget::PROPERTY_CTA] as $cta) { $widgetProperties->setWidgetProperty(TextWidget::PROPERTY_CTA . '.' . $locale . '.' . $index . '.label', $cta['label']); $widgetProperties->setWidgetProperty(TextWidget::PROPERTY_CTA . '.' . $locale . '.' . $index . '.node', $cta['node']); $widgetProperties->setWidgetProperty(TextWidget::PROPERTY_CTA . '.' . $locale . '.' . $index . '.url', $cta['url']); $widgetProperties->setWidgetProperty(TextWidget::PROPERTY_CTA . '.' . $locale . '.' . $index . '.type', $cta['type']); $index++; } } }
/** * Updates the text with the submitted data * @param \ride\web\cms\text\Text $text Text to update * @param array $data Submitted data * @return null */ public function setText(Text $text, array $data) { $format = $this->getName(); $title = isset($data[TextWidget::PROPERTY_TITLE]) ? $data[TextWidget::PROPERTY_TITLE] : null; $subtitle = isset($data[TextWidget::PROPERTY_SUBTITLE]) ? $data[TextWidget::PROPERTY_SUBTITLE] : null; $body = isset($data[TextWidget::PROPERTY_BODY]) ? $data[TextWidget::PROPERTY_BODY] : null; $image = isset($data[TextWidget::PROPERTY_IMAGE]) ? $data[TextWidget::PROPERTY_IMAGE] : null; $imageAlignment = isset($data[TextWidget::PROPERTY_IMAGE_ALIGNMENT]) ? $data[TextWidget::PROPERTY_IMAGE_ALIGNMENT] : null; $text->setFormat($this->getName()); $text->setTitle($title); $text->setSubtitle($subtitle); $text->setBody($body); $text->setImage($image); $text->setImageAlignment($imageAlignment); }
/** * Store the text in the data source * @param \ride\library\widget\WidgetProperties $widgetProperties Instance * of the widget properties * @param string|array $locale Code of the current locale * @param \ride\web\cms\text\Text $text Instance of the text * @param array $data Submitted data * @return null */ public function setText(WidgetProperties $widgetProperties, $locales, Text $text, array $submittedData) { $textModel = $this->orm->getTextModel(); $ctaModel = $this->orm->getTextCtaModel(); $locales = (array) $locales; if (isset($submittedData['version'])) { $version = $submittedData['version']; } else { $version = 0; } if (!$text instanceof TextEntry) { if (isset($submittedData['existing']) && $submittedData['existing']) { $entry = $textModel->createProxy($submittedData['existing']); } else { $entry = $textModel->createEntry(); } $entry->setFormat($text->getFormat()); $entry->setTitle($text->getTitle()); $entry->setSubtitle($text->getSubtitle()); $entry->setBody($text->getBody()); $entry->setImage($text->getImage()); $entry->setImageAlignment($text->getImageAlignment()); $text = $entry; } if ($submittedData['existing-new']) { $widgetProperties->setWidgetProperty(TextWidget::PROPERTY_TEXT, 0); $text->setEntryState(Entry::STATE_NEW); $version = 0; } elseif ($submittedData['existing']) { $widgetProperties->setWidgetProperty(TextWidget::PROPERTY_TEXT, $submittedData['existing']); if ($text->id != $submittedData['existing']) { $entry = $textModel->createProxy($submittedData['existing']); $entry->setFormat($text->getFormat()); $entry->setTitle($text->getTitle()); $entry->setSubtitle($text->getSubtitle()); $entry->setBody($text->getBody()); $entry->setImage($text->getImage()); $entry->setImageAlignment($text->getImageAlignment()); $text = $entry; } } $text->id = (int) $widgetProperties->getWidgetProperty(TextWidget::PROPERTY_TEXT); foreach ($locales as $locale) { $cta = array(); if (isset($submittedData[TextWidget::PROPERTY_CTA])) { foreach ($submittedData[TextWidget::PROPERTY_CTA] as $index => $action) { if ($action['id']) { $ctaEntry = $ctaModel->getById($action['id'], $locale, true); } else { $ctaEntry = $ctaModel->createEntry(); } $ctaEntry->setLabel($action['label']); $ctaEntry->setUrl($action['url']); $suffix = $action['suffix']; // check if suffix is set if (strlen($suffix)) { // check if it starts with # or ?. If not, prepend default # $suffix = substr($action['suffix'], 0, 1) === '?' || substr($action['suffix'], 0, 1) === '#' ? $action['suffix'] : '#' . $action['suffix']; } $ctaEntry->setSuffix($suffix); $ctaEntry->setLocale($locale); if (isset($action['node'])) { $ctaEntry->setNode($action['node']); } if (isset($action['type'])) { $ctaEntry->setType($action['type']); } $cta[$index] = $ctaEntry; } } $text->setCallToActions($cta); $text->setLocale($locale); $text->setVersion($version); $textModel->save($text); $version = $text->getVersion(); } $widgetProperties->setWidgetProperty(TextWidget::PROPERTY_TEXT, $text->id); }