mirror of
https://github.com/processwire/processwire.git
synced 2025-08-08 15:57:01 +02:00
Add support for custom fields in file/image fields. Details and instructions coming on Friday, but if you want to preview, create a template with name "field-images" where the "images" part is the name of your file/image field. Add the fields to it that you want to represent your custom fields, and it's ready to use. Supports most core Fieldtypes (including multi-language) with the following exceptions that are not supported as custom fields in an File/Image field: CKEditor, Repeaters, PageTable, Files (nested), Images (nested), Comments, Cache, Selector.
This commit is contained in:
@@ -108,6 +108,12 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
|
||||
*
|
||||
*/
|
||||
protected $formatted = false;
|
||||
|
||||
/**
|
||||
* @var Template|null
|
||||
*
|
||||
*/
|
||||
protected $fieldsTemplate = null;
|
||||
|
||||
/**
|
||||
* Construct a Pagefiles object
|
||||
@@ -117,6 +123,7 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
|
||||
*/
|
||||
public function __construct(Page $page) {
|
||||
$this->setPage($page);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -917,6 +924,44 @@ class Pagefiles extends WireArray implements PageFieldValueInterface {
|
||||
return $this->formatted;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Template object used for Pagefile custom fields, if available (false if not)
|
||||
*
|
||||
* #pw-internal
|
||||
*
|
||||
* @return bool|Template
|
||||
* @since 3.0.142
|
||||
*
|
||||
*/
|
||||
public function getFieldsTemplate() {
|
||||
if($this->fieldsTemplate === null) {
|
||||
/** @var Field $field */
|
||||
$field = $this->getField();
|
||||
if($field) {
|
||||
$this->fieldsTemplate = false;
|
||||
/** @var FieldtypeFile $fieldtype */
|
||||
$fieldtype = $field->type;
|
||||
$template = $fieldtype ? $fieldtype->getFieldsTemplate($field) : null;
|
||||
if($template) $this->fieldsTemplate = $template;
|
||||
}
|
||||
}
|
||||
return $this->fieldsTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mock/placeholder Page object used for Pagefile custom fields
|
||||
*
|
||||
* @return Page
|
||||
* @since 3.0.142
|
||||
*
|
||||
*/
|
||||
public function getFieldsPage() {
|
||||
$field = $this->getField();
|
||||
/** @var FieldtypeFile $fieldtype */
|
||||
$fieldtype = $field->type;
|
||||
return $fieldtype->getFieldsPage($field);
|
||||
}
|
||||
|
||||
/**
|
||||
* Debug info
|
||||
*
|
||||
|
Reference in New Issue
Block a user