/
FieldtypeImagePicker.module
721 lines (654 loc) · 26.2 KB
/
FieldtypeImagePicker.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
<?php
namespace ProcessWire;
/**
* Fieldtype 'Image Picker' stores a reference to an image from another page and/or folder to a selected image in the associated InputfieldImagePicker.
* The image can be rendered in template files like any Pageimage (resizing/cropping)
* In case of SVG the file contents can be rendered inline
*
* ©2019 Gerhard Sitzmann
*
* ProcessWire 3.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
* http://www.processwire.com
* http://www.ryancramer.com
*
*/
class FieldtypeImagePicker extends Fieldtype
{
/**
* Return an array of module information
*
* @return array
*/
public static function getModuleInfo()
{
return array(
'title' => __('Image Picker Fieldtype'),
'version' => 111,
'summary' => __('Fieldtype that stores a reference to a single image from another page and/or from a folder'),
'author' => 'Gerhard Sitzmann',
'href' => '',
'installs' => [
'InputfieldImagePicker',
'ImagePickerHookHelper'
],
'requires' => [
'PHP>=7.1.0',
'MySQL>=5.7.8',
'ProcessWire>=3.0.120'
],
);
}
/**
* Include classes for virtual page
* virtual pageimages on that page serve as value for images from folders
*
*/
public function __construct()
{
// require_once(dirname(__FILE__) . '/ImagePickerFile.php');
require_once(dirname(__FILE__) . '/ImagePickerVirtualpage.php');
}
/**
* Return all compatible Fieldtypes
*
* @param Field $field
* @return null
*
*/
public function ___getCompatibleFieldtypes(Field $field)
{
// there are no other fieldtypes compatible with this one
return null;
}
/**
* Sanitize the value for runtime storage and return it.
* @param Page $page
* @param Field $field
* @param string $value json string
* @return string json string
*/
public function sanitizeValue(Page $page, Field $field, $value)
{
// if it's not a json string, then return a json string with empty values
$obj = json_decode($value);
if (!isset($obj->pageid) && !isset($obj->filename)) return $this->toJson();
$value = $this->wire('sanitizer')->text($value);
return $value;
}
/**
* Get a blank value used by this fieldtype
*
* @param Page $page
* @param Field $field
* @return string json string
*
*/
public function getBlankValue(Page $page, Field $field)
{
return $this->toJson();
}
/**
* Format value for output
* @param Page $page
* @param Field $field
* @param string $value json string
* @return mixed Pageimage|null
*
*/
public function ___formatValue(Page $page, Field $field, $value)
{
$value = json_decode($value);
if ($value->filename && (int) $value->pageid === 0) { // image from folder
$pageimages = self::getPageimages($field->folderpath);
return $pageimages->getFile($value->filename);
} elseif ($value->filename && $value->pageid !== 0) { // Pageimage
$pageimage = $this->wire('pages')->get($value->pageid)->get($field->imagesfield)->getFile($value->filename);
if ($pageimage && $pageimage instanceof Pageimage) {
if(strtolower($pageimage->ext) == 'svg') $this->addHookProperty("Pageimage::svgcontent", $this, 'addPropertySvgcontent');
return $pageimage;
}
}
return null;
}
/**
* creates and returns a virtual Pageimages object with all folder images added as Pageimage
*
* @param string $folderpath can bei either full or partial disk path
* @return Pageimages
*/
static public function getPageimages($folderpath) {
// make sure $folderpath is full disk path
if(!is_dir(DIRECTORY_SEPARATOR . trim($folderpath, '/'))) $folderpath = self::getBasePath($folderpath);
$p = new ImagePickerVirtualpage($folderpath);
$field = new Field;
$field->type = new FieldtypeImage;
$field->name = 'imagepickervirtualfield';
// $field->id = 0;
$pageimages = new Pageimages($p);
$pageimages->setField($field);
$pageimages->setTrackChanges(true);
foreach(wire('files')->find($folderpath) as $file) {
$pageimage = new Pageimage($pageimages, $file);
$variation = $pageimage->isVariation(pathinfo($file, PATHINFO_BASENAME), array('allowSelf' => true, 'verbose' => false));
if($variation) continue; // add only originals
if(strtolower($pageimage->ext) == 'svg') $pageimage->set('svgcontent', FieldtypeImagePicker::getFileContent($pageimage)); // if svg, add custom property
$pageimages->add($pageimage);
}
return $pageimages;
}
/**
* Return full disk path to file
* @param Field $field
* @param object $value
* @return string
* @throws WireException
*/
public function getFilepath(Page $page, Field $field, $value)
{
$filePath = self::getBasePath($field->folderpath) . $value->filename;
$fileUrl = self::getFileUrl($field->folderpath, $value->filename);
if (file_exists($filePath)) {
return $filePath;
} else {
$field->getInputfield($page)->error("File does not exist: {$fileUrl}");
}
}
/**
* Return fill disk path to folder
*
* @param string $folderpath
* @return string disk path
*/
static public function getBasePath($folderpath)
{
return wire('config')->paths->templates . $folderpath;
}
/**
* Return file URL
* @param string $folderpath relative path to folder
* @param string $basename file basename
* @return string
*/
static public function getFileUrl($folderpath, $basename)
{
return $this->wire('config')->urls->templates . $folderpath . $basename;
}
/**
* converts values into json string
*
* @param integer $pageid
* @param string $filename
* @return string json string
*/
public static function toJson($pageid = '0', $filename = '')
{
return json_encode(array('pageid' => "{$pageid}", 'filename' => $filename));
}
/**
* Given a raw value (value as stored in database), return the value as it would appear in a Page object.
*
* @param Page $page
* @param Field $field
* @param array $value
* @return string json string
*/
public function ___wakeupValue(Page $page, Field $field, $value)
{
$obj = json_decode($value['data']);
return $this->toJson($obj->pageid, $obj->filename);
}
/**
* Given an 'awake' value, as set by wakeupValue(), convert the value back to a basic type for storage in database.
*
* @param Page $page
* @param Field $field
* @param string $value json string
* @return array properties string filename, int pageid, data json string
*/
public function ___sleepValue(Page $page, Field $field, $value)
{
$obj = json_decode($value);
$filename = $this->wire('sanitizer')->string($obj->filename);
$pageid = $this->wire('sanitizer')->int($obj->pageid);
$sleepValue = array(
'filename' => $filename,
'pageid' => $pageid,
'data' => $this->toJson($pageid, $filename)
);
return $sleepValue;
}
/**
* Return stripped file contents (only for svg)
* returns only the <svg> node from the svg document sincs this is all we need to inline an svg
* @param Pageimage $image
* @return mixed string|null
* @throws WireException
*/
static public function getFileContent($image)
{
$mimeTypes = ['image/svg', 'image/svg+xml'];
if (strtolower($image->ext) !== 'svg' || !in_array(self::getFileMimetype($image), $mimeTypes)) {
return null;
} else {
$doc = new \DOMDocument;
$doc->loadXML(file_get_contents($image->filename));
$xpath = new \DOMXPath($doc);
$xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');
$svg = $xpath->query('/svg:svg')->item(0);
if ($svg) {
return $doc->saveXML($svg);
} else {
throw new WireException("The SVG file seems corrupt. Could not find SVG tag in file");
}
}
}
/**
* Return file mime type
* @param Pageimage $image
* @return string
*/
static public function getFileMimetype($image)
{
return mime_content_type($image->filename);
}
/**
* Hook function for adding custom property 'svgcontent' to a PageImage object
*
* @param Hookevent $event
* @return string svg markup
*/
public function ___addPropertySvgcontent(Hookevent $event)
{
$event->return = self::getFileContent($event->object);
}
/**
* Return new instance of the Inputfield associated with this Fieldtype
*
* @param Page $page
* @param Field $field
* @return Inputfield
*
*/
public function getInputfield(Page $page, Field $field)
{
$inputfield = $this->modules->get('InputfieldImagePicker');
return $inputfield;
}
/**
* Return the database schema in specified format
*
* @param Field $field
* @return array
*
*/
public function getDatabaseSchema(Field $field)
{
// do not get the default schema because it assigns an index and key to data column which is not allowed for JSON data type
// $schema = parent::getDatabaseSchema($field);
// return $schema;
$engine = $this->wire('config')->dbEngine;
$charset = $this->wire('config')->dbCharset;
$schema = array(
'pages_id' => 'int UNSIGNED NOT NULL',
'data' => 'JSON NOT NULL',
'pageid' => 'INT NOT NULL',
'filename' => 'VARCHAR(255) NOT NULL',
'keys' => array(
'primary' => 'PRIMARY KEY (`pages_id`)',
'pageid' => 'KEY (`pageid`)',
'filename' => 'FULLTEXT(`filename`)'
),
// additional data
'xtra' => array(
// any optional statements that should follow after the closing paren (i.e. engine, default charset, etc)
'append' => "ENGINE=$engine DEFAULT CHARSET=$charset",
// true (default) if this schema provides all storage for this fieldtype.
// false if other storage is involved with this fieldtype, beyond this schema (like repeaters, PageTable, etc.)
'all' => true,
)
);
if ($field->id) $this->updateDatabaseSchema($field, $schema);
return $schema;
}
/**
* Update the DB schema, if necessary
*
* @param Field $field
* @param array $schema
*
*/
protected function updateDatabaseSchema(Field $field, array $schema)
{
$requiredVersion = 1;
$schemaVersion = (int) $field->get('schemaVersion');
if ($schemaVersion >= $requiredVersion) {
// already up-to-date
return;
}
if ($schemaVersion == 0) {
/**
* update schema to v2:
* add 'filename' column
* copy values from data to filename
* update column data with json string
*/
//
$schemaVersion = 1;
$database = $this->wire('database');
$table = $database->escapeTable($field->getTable());
$query = $database->prepare("SHOW TABLES LIKE '$table'");
$query->execute();
$row = $query->fetch(\PDO::FETCH_NUM);
$query->closeCursor();
if (!empty($row)) {
$query = $database->prepare("SHOW COLUMNS FROM `$table` WHERE field='pageid'");
$query->execute();
if (!$query->rowCount()) try {
$database->exec("ALTER TABLE `$table` ADD COLUMN `pageid` INT NOT NULL AFTER data");
$database->exec("ALTER TABLE `$table` ADD INDEX `pageid` (`pageid`)");
$this->message("Added 'pageid' column to '$field->table'");
// $database->exec("UPDATE `$table` SET pageid=0");
// $this->message("filled 'pageid' values with 0");
} catch (\Exception $e) {
$this->error($e->getMessage());
}
$query = $database->prepare("SHOW COLUMNS FROM `$table` WHERE field='filename'");
$query->execute();
if (!$query->rowCount()) try {
$database->exec("ALTER TABLE `$table` ADD COLUMN `filename` VARCHAR(255) NOT NULL AFTER pageid");
$database->exec("ALTER TABLE `$table` ADD FULLTEXT(`filename`)");
$this->message("Added 'filename' column to '$field->table'");
$database->exec("UPDATE `$table` SET filename=data");
$this->message("copied 'data' values to 'filename' column");
$database->exec("UPDATE `$table` SET `data`=''");
$database->exec("ALTER TABLE `$table` DROP KEY data");
$database->exec("UPDATE `$table` SET data=CONCAT(JSON_OBJECT(\"pageid\", `$table`.pageid, \"filename\", `$table`.filename))");
$this->message("populated 'data'");
$database->exec("ALTER TABLE `$table` MODIFY data JSON NOT NULL");
$this->message("updated 'data' schema to JSON");
} catch (\Exception $e) {
$this->error($e->getMessage());
}
}
}
$field->set('schemaVersion', $schemaVersion);
// @todo: this should go into ___update() but it is ot being triggered there
if($field->get('folderPath')) {
$field->set('folderpath', $field->get('folderPath'));
$field->set('fromfolder', 1);
}
$field->save();
$this->wire('log')->save('modules', 'updated DB table');
}
/**
* Match values for PageFinder
*
* @param DatabaseQuerySelect $query
* @param string $table
* @param string $subfield
* @param string $operator
* @param string $value
* @return DatabaseQuerySelect
*
*/
public function getMatchQuery($query, $table, $subfield, $operator, $value)
{
$database = $this->wire("database");
if (empty($subfield) || $subfield == "data") {
$path = '$.*';
} else {
$path = '$.' . $subfield;
}
$table = $database->escapeTable($table);
$value = $database->escapeStr($value);
if ($operator == "=") {
$query->where("JSON_SEARCH({$table}.data, 'one', '$value', NULL, '$path') IS NOT NULL");
} else if ($operator == "*=" || $operator == "%=") {
$query->where("JSON_SEARCH({$table}.data, 'one', '%$value%', NULL, '$path') IS NOT NULL");
} else if ($operator == "^=") {
$query->where("JSON_SEARCH({$table}.data, 'one', '$value%', NULL, '$path') IS NOT NULL");
} else if ($operator == "$=") {
$query->where("JSON_SEARCH({$table}.data, 'one', '%$value', NULL, '$path') IS NOT NULL");
}
return $query;
}
public function ___upgrade($fromVersion, $toVersion)
{
if (version_compare($fromVersion, $toVersion == -1)) {
$modules = $this->wire('modules');
// install helper module
if (!$modules->isInstalled('ImagePickerHookHelper')) $modules->install('ImagePickerHookHelper');
$this->wire('log')->save('modules', 'installed module ImagePickerHookHelper');
// update field settings
foreach ($this->wire('fields') as $field) {
var_dump($field);
if (!$field->get('folderPath')) continue;
// @todo for some reason this code does not run
$field->set('folderpath', $field->get('folderPath'));
$field->set('folderPath', 'deprecated');
$field->set('fromfolder', 1);
$field->save();
$this->wire('log')->save('modules', "updated field {$field->name} settings");
}
}
}
/**
* Get the inputfield used for configuration of this Fieldtype.
*
* @param Field $field
* @return InputfieldWrapper
*
*/
public function ___getConfigInputfields(Field $field)
{
$errorimgpage = false;
if ($field->imagespage) {
$hasImagefield = false;
$imagespage = $this->pages->get("id={$field->imagespage}, include=hidden");
foreach ($imagespage->fieldgroup as $f) {
if ($f->type instanceof FieldtypeImage) {
$hasImagefield = true;
break;
}
}
if (!$hasImagefield) {
$errorimgpage = $this->_("The selected page has no field for images. Choose a page with images field or add an images field to this page's template");
}
}
$errorfolder = false;
if ($field->fromfolder && $field->folderpath) {
$folder = $this->config->paths->templates . ltrim($field->folderpath, '/');
$path = $this->config->urls->templates . ltrim($field->folderpath, '/');
if ($field->folderpath && !is_dir($folder)) {
$errorfolder = sprintf($this->_("Folder %s doesn't exist."), $path);
} elseif ($field->folderpath && count(scandir($folder)) == 2) {
$errorfolder = sprintf($this->_("Folder %s is empty. You need to upload images."), $path);
}
}
$inputfields = parent::___getConfigInputfields($field);
$sourceswrapper = new InputfieldFieldset;
$sourceswrapper->label = $this->_("Choose Image sources");
/* images from pages*/
$wrapper = new InputfieldFieldset;
$wrapper->label = $this->_("Pick images from a page?");
/**
* @var Field
*/
$f = $this->modules->get('InputfieldCheckbox');
$f->attr('name', 'frompages');
$f->label = $this->_("Pick images from a page?");
// $f->description = $this->_('If checked, all child pages of above page will serve images to the inputfield');
$f->attr('checked', $field->frompages ? 'checked' : '');
$f->attr('value', $field->frompages);
$wrapper->add($f);
/**
* @var Field
*/
$f = $this->modules->get('InputfieldPageListSelect');
$f->attr('name', 'imagespage');
$f->parent_id = 0; // 0 to include homepage
$f->label = $this->_("Choose a page to get images from");
$f->description = $this->_("This page will be used to supply images");
$f->attr('value', $field->imagespage);
$f->showIf('frompages=1');
$f->requiredIf('frompages=1');
$f->getErrors(true);
if ($errorimgpage) $f->error($errorimgpage);
$wrapper->add($f);
if (!$errorimgpage) {
/**
* @var Field
*/
$f = $this->modules->get('InputfieldRadios');
$f->attr('name', 'imagesfield');
$f->optionColumns = 1;
$f->showIf('frompages=1');
$f->requiredIf('imagespage!=""');
if ($field->imagespage) {
$f->label = $this->_("Choose an images field on the template of the page above");
$f->required(1);
$fields = $imagespage->fieldgroup->find('type=FieldtypeImage');
$options = array();
foreach ($fields as $fd) $options[$fd->name] = $fd->name;
$f->options = $options;
$f->attr('value', $field->imagesfield);
} else {
$f->label = $this->_("You must submit changes to the field above first");
}
$wrapper->add($f);
}
/**
* @var Field
*/
$f = $this->modules->get('InputfieldCheckbox');
$f->attr('name', 'includechildren');
$f->label = $this->_("Include child pages of above page as source for images?");
$f->description = $this->_('If checked, all child pages of above page will also supply images to the inputfield');
$f->attr('checked', $field->includechildren ? 'checked' : '');
$f->attr('value', $field->includechildren);
$f->showIf('frompages=1');
$wrapper->add($f);
$sourceswrapper->add($wrapper);
/* images from folder*/
$wrapper = new InputfieldFieldset;
$wrapper->label = $this->_("Pick images from a defined folder?");
/**
* @var Field
*/
$f = $this->modules->get('InputfieldCheckbox');
$f->attr('name', 'fromfolder');
$f->label = $this->_("Pick images from a defined folder?");
// $f->description = $this->_('If checked, all child pages of above page will serve images to the inputfield');
$f->attr('checked', $field->fromfolder ? 'checked' : '');
$f->attr('value', $field->fromfolder);
$wrapper->add($f);
/**
* @var Field
*/
$f = $this->modules->get('InputfieldText');
$f->attr('name', 'folderpath');
$f->label = $this->_("The folder containing the images.");
$f->attr('value', $field->folderpath);
$f->description =
sprintf($this->_('A path relative to the **%s** folder.'), $this->config->urls->templates);
$f->notes =
$this->_("When the files are located in /site/templates/images/icons/, type: images/icons/");
$f->getErrors(true);
if ($errorfolder) $f->error($errorfolder);
$f->showIf('fromfolder=1');
if ($field->fromfolder) $f->required(1);
if ($field->fromfolder && !$field->folderpath) $f->error('You must enter a folder path');
$wrapper->add($f);
$sourceswrapper->add($wrapper);
/* images from page*/
$wrapper = new InputfieldFieldset;
$wrapper->label = $this->_("Pick images from the page the field lives on?");
/**
* @var Field
*/
$f = $this->modules->get('InputfieldCheckbox');
$f->attr('name', 'frompage');
$f->label2 = $this->_("Pick from the page the field lives on?");
$f->skipLabel(4);
$f->description = $this->_('Images from the page that this field is on, will be supplied. The page must have an images field for this option to work.');
$f->attr('checked', $field->frompage ? 'checked' : '');
$f->attr('value', $field->frompage);
$wrapper->add($f);
/**
* @var Field
*/
$f = $this->modules->get('InputfieldRadios');
$f->attr('name', 'imagesfieldpage');
$f->optionColumns = 1;
$f->showIf('frompage=1');
$f->requiredIf('frompage=1');
if ($field->frompage) {
$f->label = $this->_("Choose an images field to use");
$f->description = $this->_('Images from this field will be supplied. For this option to work, the page must have this images field.');
$f->required(1);
$fields = $this->wire('fields')->find('type=FieldtypeImage');
$options = array();
foreach ($fields as $fd) $options[$fd->name] = $fd->name;
$f->options = $options;
$f->attr('value', $field->imagesfieldpage);
} else {
$f->label = $this->_("You must submit changes to the field above first");
}
$wrapper->add($f);
$sourceswrapper->add($wrapper);
$inputfields->add($sourceswrapper);
/* general settings */
$wrapper = new InputfieldFieldset;
$wrapper->label = $this->_("General settings");
/**
* @var Field
*/
$f = $this->modules->get('InputfieldCheckbox');
$f->attr('name', 'useajax');
$f->label = $this->_("Load thumbnails dynamically only when requested");
$f->description = $this->_('If checked, the thumbnail images will be loaded on demand. Especially useful when field is used inside repeaters or has many images');
$f->attr('checked', $field->useajax ? 'checked' : '');
$f->attr('value', $field->useajax);
// $inputfields->add($f);
$wrapper->add($f);
/**
* @var Field
*/
$f = $this->modules->get('InputfieldText');
$f->attr('name', 'previewWidth');
$f->label = $this->_("Width of the selected image in px");
$f->description = $this->_('Sets the width of the selected image inside the inputfield, defaults to 200px');
$f->attr('value', $field->previewWidth);
// $inputfields->add($f);
$wrapper->add($f);
/**
* @var Field
*/
$f = $this->modules->get('InputfieldText');
$f->attr('name', 'thumbWidth');
$f->label = $this->_("Width of thumbnail images in px");
$f->description = $this->_('Sets the width of the thumbnail images inside the input field, defaults to 100px');
$f->attr('value', $field->thumbWidth);
// $inputfields->add($f);
$wrapper->add($f);
$inputfields->add($wrapper);
/**
* @var Field
*/
$f = $this->modules->get('InputfieldMarkup');
$f->attr('name', 'FieldtypeImagePicker_instructions');
$f->label = $this->_("How to use this field in a template");
$f->attr('value', '<code><img src="<?= $page->' . $field->name . '->url ?>"> // renders the image<br>
$page->' . $field->name . '->svgcontent // returns the text content for inlining SVG (works only with SVG images)<br><br>
All properties and methods for Pageimage can be used (resizing, cropping etc.)<br>
$thumb = $page->' . $field->name . '->width(100)<br><br>
Field is fully searchable for image filename by API<br>
$pages->find("' . $field->name . '.filename=xyz.png")
</code>');
$inputfields->add($f);
return $inputfields;
}
}