/** * 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++; } } }
/** * Write the properties of the content to the widget properties * @param \ride\library\widget\WidgetSettings $properties * @return null */ public function setToWidgetProperties(WidgetProperties $properties, $locale) { $fields = null; if ($this->modelFields) { $fields = implode(self::SEPARATOR, $this->modelFields); } $properties->setWidgetProperty(self::PROPERTY_MODEL_NAME, $this->modelName); $properties->setWidgetProperty(self::PROPERTY_ENTRY, $this->entryId); $properties->setWidgetProperty(self::PROPERTY_MODEL_FIELDS, $fields); $properties->setWidgetProperty(self::PROPERTY_RECURSIVE_DEPTH, $this->recursiveDepth); $properties->setWidgetProperty(self::PROPERTY_INCLUDE_UNLOCALIZED, $this->includeUnlocalized); $properties->setWidgetProperty(self::PROPERTY_SEARCH, $this->hasSearch ? '1' : '0'); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_CONDITION, $this->condition); $properties->setWidgetProperty(self::PROPERTY_ORDER, $this->order); $properties->setWidgetProperty(self::PROPERTY_PAGINATION_ENABLE, $this->isPaginationEnabled); if ($this->isPaginationEnabled) { $properties->setWidgetProperty(self::PROPERTY_PAGINATION_ROWS, $this->paginationRows); $properties->setWidgetProperty(self::PROPERTY_PAGINATION_OFFSET, $this->paginationOffset); $properties->setWidgetProperty(self::PROPERTY_PAGINATION_SHOW, $this->showPagination); $properties->setWidgetProperty(self::PROPERTY_PAGINATION_AJAX, $this->useAjaxForPagination); if ($this->showMore) { $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_MORE_SHOW, $this->showMore); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_MORE_LABEL, $this->moreLabel); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_MORE_NODE, $this->moreNode); } else { $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_MORE_SHOW, null); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_MORE_LABEL, null); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_MORE_NODE, null); } } else { $properties->setWidgetProperty(self::PROPERTY_PAGINATION_ROWS, null); $properties->setWidgetProperty(self::PROPERTY_PAGINATION_OFFSET, null); $properties->setWidgetProperty(self::PROPERTY_PAGINATION_SHOW, null); $properties->setWidgetProperty(self::PROPERTY_PAGINATION_AJAX, null); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_MORE_SHOW, null); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_MORE_LABEL, null); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_MORE_NODE, null); } $properties->setWidgetProperty(self::PROPERTY_ID_FIELD, $this->idField); $properties->setWidgetProperty(self::PROPERTY_PRIMARY, $this->isPrimaryMapper); $properties->setWidgetProperty(self::PROPERTY_MAPPER, $this->contentMapper); $properties->setWidgetProperty(self::PROPERTY_TEMPLATE, $this->template); $properties->setWidgetProperty(self::PROPERTY_VIEW_PROCESSOR, $this->viewProcessor); $properties->setWidgetProperty(self::PROPERTY_FORMAT_TITLE, $this->contentTitleFormat); $properties->setWidgetProperty(self::PROPERTY_FORMAT_TEASER, $this->contentTeaserFormat); $properties->setWidgetProperty(self::PROPERTY_FORMAT_IMAGE, $this->contentImageFormat); $properties->setWidgetProperty(self::PROPERTY_FORMAT_DATE, $this->contentDateFormat); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_TITLE, $this->title); $properties->setWidgetProperty(self::PROPERTY_EMPTY_RESULT_VIEW, $this->emptyResultView ? '1' : '0'); $properties->setLocalizedWidgetProperty($locale, self::PROPERTY_EMPTY_RESULT_MESSAGE, $this->emptyResultMessage); $properties->setWidgetProperty(self::PROPERTY_META_OG, $this->metaOg); $properties->setWidgetProperty(self::PROPERTY_FORMAT_TITLE_OG, $this->ogTitleFormat); $properties->setWidgetProperty(self::PROPERTY_FORMAT_TEASER_OG, $this->ogTeaserFormat); $properties->setWidgetProperty(self::PROPERTY_FORMAT_IMAGE_OG, $this->ogImageFormat); $properties->setWidgetProperty(self::PROPERTY_BREADCRUMB, $this->breadcrumb ? '1' : '0'); $parameters = $this->parameters; if ($parameters) { if (is_array($parameters)) { $parameters = implode(self::SEPARATOR, $parameters); } $properties->setWidgetProperty(self::PROPERTY_PARAMETERS, $parameters); } else { $properties->setWidgetProperty(self::PROPERTY_PARAMETERS, null); } $properties->setWidgetProperty(self::PROPERTY_PARAMETERS_NONE, $this->parametersNone); $filters = $this->filters; if (is_array($filters)) { $filterValues = array(); foreach ($filters as $filter) { $filterValues[] = $filter['name'] . ':' . $filter['type'] . ':' . $filter['field']; } $properties->setWidgetProperty(self::PROPERTY_FILTERS, implode(self::SEPARATOR, $filterValues)); } else { $properties->setWidgetProperty(self::PROPERTY_FILTERS, null); } }
/** * 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); }