/**
  * Gets the text from the data source
  * @param \ride\library\widget\WidgetProperties $widgetProperties Instance
  * of the widget properties
  * @param string $locale Code of the current locale
  * @return \ride\web\cms\text\Text Instance of the text
  */
 public function getText(WidgetProperties $widgetProperties, $locale)
 {
     $callToActions = array();
     $widgetProperties->getWidgetProperties(TextWidget::PROPERTY_CTA . '.' . $locale);
     foreach ($widgetProperties as $key => $value) {
         $keyTokens = explode('.', $key);
         if (count($keyTokens) < 3) {
             continue;
         }
         if (!isset($callToActions[$keyTokens[2]])) {
             $callToActions[$keyTokens[2]] = new GenericCallToAction();
         }
         $method = 'set' . ucfirst($keyTokens[3]);
         $callToActions[$keyTokens[2]]->{$method}($value);
     }
     $text = new GenericText();
     $text->setFormat($widgetProperties->getLocalizedWidgetProperty($locale, TextWidget::PROPERTY_FORMAT));
     $text->setTitle($widgetProperties->getLocalizedWidgetProperty($locale, TextWidget::PROPERTY_TITLE));
     $text->setSubtitle($widgetProperties->getLocalizedWidgetProperty($locale, TextWidget::PROPERTY_SUBTITLE));
     $text->setBody($widgetProperties->getLocalizedWidgetProperty($locale, TextWidget::PROPERTY_BODY));
     $text->setImage($widgetProperties->getLocalizedWidgetProperty($locale, str_replace('-', '.', TextWidget::PROPERTY_IMAGE)));
     $text->setImageAlignment($widgetProperties->getLocalizedWidgetProperty($locale, str_replace('-', '.', TextWidget::PROPERTY_IMAGE_ALIGNMENT)));
     $text->setCallToActions($callToActions);
     return $text;
 }
 /**
  * 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);
     }
 }
 /**
  * Adds a warning to the response if the provided text is used in another
  * widget instance
  * @param \ride\library\widget\WidgetProperties $widgetProperties
  * @param \ride\web\cms\orm\model\TextModel $textModel
  * @param \ride\web\cms\text\Text $text Instance of the text
  * @param string $warning
  * @return null
  */
 protected function warnAboutUsedText(WidgetProperties $widgetProperties, TextModel $textModel, Text $text, $warning)
 {
     if (!$text->id) {
         return;
     }
     $widgetId = $widgetProperties->getWidgetId();
     $node = $widgetProperties->getNode();
     $rootNode = $node->getRootNode();
     $nodes = $this->nodeModel->getNodesForWidget(TextWidget::NAME, $rootNode->getId());
     foreach ($nodes as $node) {
         $nodeWidgetId = $node->getWidgetId();
         if ($nodeWidgetId == $widgetId) {
             continue;
         }
         $nodeWidgetProperties = $node->getWidgetProperties($nodeWidgetId);
         if ($nodeWidgetProperties->getWidgetProperty(TextWidget::PROPERTY_IO) !== self::NAME) {
             continue;
         }
         if ($nodeWidgetProperties->getWidgetProperty(TextWidget::PROPERTY_TEXT) !== $text->id) {
             continue;
         }
         $message = new Message($warning, Message::TYPE_WARNING);
         $this->response->addMessage($message);
         break;
     }
 }