/** * @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(); }
/** * @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(); }
/** * @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(); }
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(); }