public function validate($value)
 {
     if (is_array($value) && $value['type'] != '') {
         $linkModel = $this->_valueToModel($value);
         $validated = $linkModel->validate();
         return $validated ? true : $linkModel->getAllErrors();
     }
     parent::validate($value);
 }
Esempio n. 2
0
 /**
  * @inheritDoc IFieldType::getSearchKeywords()
  *
  * @param mixed $value
  *
  * @return string
  */
 public function getSearchKeywords($value)
 {
     $criteria = $this->prepValue(null);
     $keywords = array();
     $contentService = craft()->content;
     foreach ($criteria->find() as $block) {
         $originalContentTable = $contentService->contentTable;
         $originalFieldColumnPrefix = $contentService->fieldColumnPrefix;
         $originalFieldContext = $contentService->fieldContext;
         $contentService->contentTable = $block->getContentTable();
         $contentService->fieldColumnPrefix = $block->getFieldColumnPrefix();
         $contentService->fieldContext = $block->getFieldContext();
         foreach (craft()->fields->getAllFields() as $field) {
             $fieldType = $field->getFieldType();
             if ($fieldType) {
                 $fieldType->element = $block;
                 $handle = $field->handle;
                 $keywords[] = $fieldType->getSearchKeywords($block->getFieldValue($handle));
             }
         }
         $contentService->contentTable = $originalContentTable;
         $contentService->fieldColumnPrefix = $originalFieldColumnPrefix;
         $contentService->fieldContext = $originalFieldContext;
     }
     return parent::getSearchKeywords($keywords);
 }
 /**
  * @inheritDoc IFieldType::getSearchKeywords()
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return string
  */
 public function getSearchKeywords($criteria)
 {
     $titles = array();
     foreach ($criteria->find() as $element) {
         $titles[] = (string) $element;
     }
     return parent::getSearchKeywords($titles);
 }
 /**
  * @inheritDoc IFieldType::onAfterElementSave()
  *
  * @return null
  */
 public function onAfterElementSave()
 {
     $element = $this->element;
     $content = $element->getContent();
     $fieldHandle = $this->model->handle;
     if (empty($fieldHandle)) {
         $defaultField = $this->prepValue(null);
         $content->setAttribute($field->handle, $defaultField);
         $element->setContent($content);
         craft()->content->saveContent($element);
     }
     parent::onAfterElementSave();
 }
 /**
  * Get search keywords.
  *
  * @param ElementCriteriaModel|array $criteria
  *
  * @return array
  */
 public function getSearchKeywords($criteria)
 {
     // Behave normally in cp
     if (craft()->request->isCpRequest()) {
         return parent::getSearchKeywords($criteria);
     }
     // Or parse youtube video models
     $titles = array();
     foreach ($criteria as $element) {
         $titles[] = (string) $element;
     }
     return BaseFieldType::getSearchKeywords($titles);
 }
Esempio n. 6
0
 /**
  * @inheritDoc IFieldType::onAfterElementSave()
  *
  * @return null
  */
 public function onAfterElementSave()
 {
     $fieldHandle = $this->model->handle;
     $attributes = $this->element->content->attributes;
     $retourModel = null;
     if (isset($attributes[$fieldHandle])) {
         $retourModel = $attributes[$fieldHandle];
     }
     $value = $this->prepValueFromPost($retourModel);
     if ($value) {
         RetourPlugin::log("Resaving Retour field data", LogLevel::Info, false);
         /* -- If the redirectSrcUrl is empty, don't save it, and delete any existing record */
         if ($value->redirectSrcUrl == "") {
             craft()->retour->deleteRedirectByElementId($value->associatedElementId, $value->locale);
         } else {
             $error = craft()->cache->flush();
             RetourPlugin::log("Cache flushed: " . print_r($error, true), LogLevel::Info, false);
             craft()->retour->saveRedirect($value);
         }
     }
     parent::onAfterElementSave();
 }
 /**
  * Returns the search keywords that should be associated with this field,
  * based on the prepped post data.
  *
  * @param mixed $value
  * @return string
  */
 public function getSearchKeywords($value)
 {
     $elements = $this->prepValue(null);
     $titles = array();
     foreach ($elements->all as $element) {
         $titles[] = (string) $element;
     }
     return parent::getSearchKeywords($titles);
 }
 /**
  * @inheritDoc IFieldType::onAfterElementSave()
  *
  * @return null
  */
 public function onAfterElementSave()
 {
     $element = $this->element;
     $content = $element->getContent();
     $fieldHandle = $this->model->handle;
     $shouldResave = false;
     if (empty($fieldHandle)) {
         $shouldResave = true;
     }
     if (!isset($content[$fieldHandle])) {
         $shouldResave = true;
     } else {
         if (empty($content[$fieldHandle])) {
             $shouldResave = true;
         }
     }
     if ($shouldResave) {
         $defaultField = $this->prepValue(null);
         $content->setAttribute($fieldHandle, $defaultField);
         $element->setContent($content);
         craft()->content->saveContent($element);
     }
     parent::onAfterElementSave();
 }
 public function onAfterElementSave()
 {
     $handle = $this->model->handle;
     $data = $this->element->{$handle};
     foreach ($data->markers as $index => $marker) {
         if ($marker->deleted) {
             if (isset($marker->locationId)) {
                 $location = GoogleMaps_LocationRecord::model()->findByPk($marker->locationId);
                 if ($location) {
                     $location->delete();
                 }
             }
             $data->removeMarker($index);
         } else {
             $marker->isNew = false;
             $marker->elementId = $this->element->id;
             $location = GoogleMaps_LocationRecord::model()->findByPk(isset($marker->locationId) ? $marker->locationId : 0);
             if (!$location) {
                 $location = new GoogleMaps_LocationRecord();
                 $location->elementId = $this->element->id;
                 $location->handle = $handle;
             }
             $location->address = $marker->address;
             $location->addressComponents = $marker->addressComponents;
             $location->title = $marker->title;
             $location->content = $marker->content;
             $location->lat = $marker->lat;
             $location->lng = $marker->lng;
             $location->save();
             $marker->locationId = $location->id;
         }
     }
     foreach ($data->polygons as $index => $polygon) {
         if ($polygon->deleted) {
             $data->removePolygon($index);
         } else {
             $polygon->elementId = $this->element->id;
             $polygon->isNew = false;
         }
     }
     foreach ($data->polylines as $index => $polyline) {
         if ($polyline->deleted) {
             $data->removePolyline($index);
         } else {
             $polyline->elementId = $this->element->id;
             $polyline->isNew = false;
         }
     }
     foreach ($data->routes as $index => $route) {
         if ($route->deleted) {
             $data->removeRoute($index);
         } else {
             $route->elementId = $this->element->id;
             $route->isNew = false;
         }
     }
     foreach ($data->circles as $index => $circle) {
         if ($circle->deleted) {
             $data->removeCircle($index);
         } else {
             $circle->elementId = $this->element->id;
             $circle->isNew = false;
         }
     }
     foreach ($data->groundOverlays as $index => $overlay) {
         if ($overlay->deleted) {
             $data->removeGroundOverlay($index);
         } else {
             $overlay->elementId = $this->element->id;
             $overlay->isNew = false;
         }
     }
     if (isset($this->element->{$handle})) {
         $this->element->getContent()->{$handle} = $data->toJson();
         craft()->content->saveContent($this->element);
     }
     parent::onAfterElementSave();
 }