Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #3 from PawelGIX/master

configuration settings moved to CropImage field settings
  • Loading branch information...
commit 623ee390b62dacee107b34880709a3f0d3234d0b 2 parents e3de3e5 + c670435
@apeisa authored
View
58 FieldtypeCropImage.module
@@ -18,8 +18,24 @@ class FieldtypeCropImage extends FieldtypeImage {
$thumbFound = false;
$thumb = $event->arguments[0];
- $crops = wire('modules')->get('ProcessCropImage')->crops;
+
+
+ // return InputfieldCropImage or null if not found
+ $inputFieldInstance = $this->_getInputFieldInstance($event);
+
+ if(!$inputFieldInstance)
+ return true;
+
+ // read crop settings from InputfieldCropImage
+ $crops = $inputFieldInstance->thumbSetting;
+
+ // and we continue...
+
+
+
+
+
$crops_a = explode("\n", $crops); // ie. thumbname,200,200 (name,width,height)
foreach($crops_a as $crop) {
@@ -67,6 +83,46 @@ class FieldtypeCropImage extends FieldtypeImage {
}
return true;
}
+
+
+
+ public function _getInputFieldInstance(HookEvent $event) {
+
+
+ $field = null; // where we'll keep the field we're looking for
+ $image = $event->object;
+ $page = $image->page;
+ $action = $event->arguments[0];
+
+ // find all fields of type FieldtypeImage that are part of the page we're using
+ $imageFields = $page->fields->find('type=FieldtypeCropImage');
+
+ // loop through to find the one we're looking for
+ foreach($imageFields as $imageField) {
+
+ // good to get unformatted in case it's a single image field,
+ // because it'll still be an array rather than 1 image
+ $pagefiles = $page->getUnformatted($imageField->name);
+
+
+ // if the image's pagefiles property matches the one with the
+ // field we're looking at, we have a match. save in $field
+ if($image->pagefiles === $pagefiles) {
+ $field = $imageField;
+ break;
+ }
+ }
+
+ if($field) {
+ //$event->return = $out;
+ return $field;
+ }
+
+ return null;
+ }
+
+
+
public function install() {
parent::___install();
View
44 InputfieldCropImage/InputfieldCropImage.module
@@ -13,6 +13,9 @@ class InputfieldCropImage extends InputfieldImage {
public function init() {
parent::init();
+
+ //default settings
+ $this->set('thumbSetting', 'thumbnail,100,100');
}
public function ___render() {
@@ -25,7 +28,9 @@ class InputfieldCropImage extends InputfieldImage {
$out = parent::renderItem($pagefile, $id, $n);
- $crops = $this->modules->get('ProcessCropImage')->crops;
+
+ $crops = $this->thumbSetting;
+
if (strlen($crops) > 3) {
// If we've defined one or more templates for specific crops, we need to check the current page's template to see if we actually have any applicable crops to show to the user
$page = $this->pages->get($this->input->get->id);
@@ -44,8 +49,10 @@ class InputfieldCropImage extends InputfieldImage {
}
$applicableCrops = implode("\n", $applicableCrops);
$cropUrl = "../image-crop/";
+
if (!empty($applicableCrops)) {
$cropLinks = $this->_getCropLinks($crops, $cropUrl, $pagefile);
+
if (!empty($cropLinks)) {
$cropStr = "\n\t\t\t<div class='ui-widget-content crops'><p class='description'>Thumbnails (hover to preview, click to crop)</p>". $this->_getCropLinks($applicableCrops, $cropUrl, $pagefile) . "</div>";
// We add our crop string at the end of the list item that holds image
@@ -75,6 +82,41 @@ class InputfieldCropImage extends InputfieldImage {
if ($this->modules->get('ProcessCropImage')->cropOriginal) {
$out .= "<a target='_blank' data-thumburl='{$thumbUrl}' class='cropOriginal' href='$cropUrl?filename={$pagefile->basename}&pages_id={$this->input->get->id}&field={$this->name}&modal=1'>ORIGINAL</a>";
}
+
+
+
return $out;
}
+
+
+
+
+ public function ___getConfigInputfields() {
+
+ $inputfields = parent::___getConfigInputfields();
+
+
+ /*
+ $fieldset = $this->modules->get('InputfieldFieldset');
+ $fieldset->label = $this->_("Thumbnails Settings");
+ $fieldset->collapsed = $this->maxWidth || $this->maxHeight ? Inputfield::collapsedNo : Inputfield::collapsedYes;
+ $fieldset->description = $this->_('Enter all crop dimensions, one on each line and in this format: name,width,height. Few examples: "thumbnail,200,200" or "portrait,200,600"');
+ */
+
+
+ $field = $this->modules->get("InputfieldTextarea");
+ $field->attr('name', 'thumbSetting');
+ $field->attr('value', (string) $this->thumbSetting );
+ $field->label = $this->_("Thumbnail Settings");
+ $field->description = $this->_('Enter all crop dimensions, one on each line in this format: name,width,height. Few examples: "thumbnail,200,200" or "portrait,200,600". Optionally, you can limit the visibility of the thumbnails to the selected template, giving as the last parameter, the name of the template. Example: "thumbnail,200,200,base-page,home"');
+
+ //$fieldset->add($field);
+
+ $inputfields->add($field);
+
+ return $inputfields;
+ }
+
+
+
}
View
7 ProcessCropImage/ProcessCropImage.module
@@ -4,7 +4,7 @@ class ProcessCropImage extends Process implements ConfigurableModule {
public static function getModuleInfo() {
return array(
'title' => 'Image cropping tool',
- 'summary' => 'Crop thumbnails (this is where you edit your crop setups)',
+ 'summary' => 'Crop thumbnails (Configuration Settings moved to CropImage field settings).',
'href' => 'http://processwire.com/talk/index.php/topic,705.0.html',
'version' => 100,
'permanent' => false,
@@ -172,7 +172,8 @@ FORM;
$f->attr('checked', empty($data['cropOriginal']) ? '' : 'checked');
$fields->append($f);
*/
-
+
+ /* OLD CONFIGURATION
$f = $modules->get('InputfieldTextarea');
$f->attr('name', 'crops');
$f->attr('rows', 5);
@@ -180,7 +181,7 @@ FORM;
$f->label = 'Crop setups';
$f->description = 'Enter all crop dimensions, one on each line and in this format: name,width,height. Few examples: "thumbnail,200,200" or "portrait,200,600"';
$fields->append($f);
-
+ */
return $fields;
}
View
4 README
@@ -4,11 +4,11 @@ How to install
Just add files and folders to your site/modules/ folder and install one of the modules (it installs others). After that create new field or edit existing image field and make it use fieldtype "CropImage".
-You can modify crop setups for your site from "Image cropping tool" module under Process. Put each of the setups on their own line, like this:
+You can change the settings for each field in the Setup->Files->CropImageField Input tab:
thumbnail,100,100
portrait,100,150
-largethumb,200,200
+largethumb,200,200,basic-page,home
Usage on templates
Please sign in to comment.
Something went wrong with that request. Please try again.