Gideon So Posted November 13 Posted November 13 I have a Tinymce textarea field reside in a repeater. I want to insert an image to the editor and I click the insert image button. It open a modal show images from the current repeater item page. Of course there is no images inside the page. I need to click the "change" link and then find the page I have the image, Is it possible to make the Tinymce insert image plugin to show repeater forPage? Gideon
hellomoto Posted November 28 Posted November 28 (edited) When I try a repeater item that contains a TinyMCE field on a forPage, the forPage's images are displayed by this module ($masterPage in the class) Edited November 28 by hellomoto
hellomoto Posted November 28 Posted November 28 (edited) This works to replace the ___execute method to select a default page for pages that don't contain image fields: public function ___execute() { if($this->config->demo) throw new WireException("Sorry, image editing functions are disabled in demo mode"); if(!$this->page) { $error = "No page provided"; $this->error($error); return "<p>$error</p>"; } $sanitizer = $this->wire()->sanitizer; $modules = $this->wire()->modules; $input = $this->wire()->input; $images = $this->getImages($this->page, $this->page->fields); $pickpage = false; // locate any image fields $imageFields = $this->getImageFields($this->page); if (!wireCount($imageFields)) { $default = @$this->data['defaultPage'] ?: false; if ($default > 0) { $pg = $this->wire->pages->get($default); if ($pg->id > 0) { $this->page = $pg; $pickpage = true; } } // Selector page by template selection in module config: $pgByTpl = @$this->data['templateDefaultPage']; if (!empty($pgByTpl)) { $lines = explode("\n", $pgByTpl); foreach ($lines as $line) { $pcs = explode(':', $line); if (count($pcs) < 2) continue; $tpl = wire('templates')->get($pcs[0]); $pg = wire('pages')->get($pcs[1]); if ($tpl->id == $this->editorPage->template->id) { $pickpage = true; $this->page = $pg; break; } } } if ($pickpage) $this->message('Default images selection page set'); $images = $this->getImages($this->page, $this->page->fields); // locate image fields from default $imageFields = $this->getImageFields($this->page); } if(wireCount($imageFields)) { $imageFieldNames = implode(',', array_keys($imageFields)); /** @var InputfieldButton $btn */ $btn = $modules->get('InputfieldButton'); $uploadOnlyMode = "$this->page" === "$this->editorPage" ? 1 : 2; $btn->href = "../edit/?modal=1&id={$this->page->id}&fields=$imageFieldNames&uploadOnlyMode=$uploadOnlyMode"; $btn->value = $this->_('Upload Image'); $btn->addClass('upload pw-modal-button pw-modal-button-visible'); $btn->icon = 'upload'; $changes = $input->get('changes'); if($changes) { foreach(explode(',', $changes) as $name) { $name = $sanitizer->fieldName($name); $field = $this->wire()->fields->get($name); if(!$field) continue; $out .= "<script>refreshPageEditField('$name');</script>"; } } } else $btn = null; if($this->input->get('file')) return $this->executeEdit(); // initialization of variables was here $out = ''; if(wireCount($images)) { $winwidth = (int) $input->get('winwidth'); $in = $modules->get('InputfieldImage'); /** @var InputfieldImage $in */ $in->set('adminThumbs', true); $lastFieldLabel = ''; $numImageFields = 0; foreach($images as $image) { /** @var PageImage $image */ $fieldLabels = array(); $parentFields = $image->get('_parentFields'); if(!is_array($parentFields)) $parentFields = array(); foreach($parentFields as $parentField) { $fieldLabels[] = $parentField->getLabel(); } $fieldLabels[] = $image->field->getLabel(); $fieldLabel = implode(' > ', $fieldLabels); if($fieldLabel != $lastFieldLabel) { $numImageFields++; $out .= "\n\t<li class='select_images_field_label detail'>" . $sanitizer->entities($fieldLabel) . "</li>"; } $lastFieldLabel = $fieldLabel; if($this->noThumbs) { $width = $image->width(); $alt = $sanitizer->entities1($image->description); if($width > $this->maxImageWidth) $width = $this->maxImageWidth; $img = "<img src='$image->URL' width='$width' alt=\"$alt\" />"; } else { $image->set('_requireHeight', true); // recognized by InputfieldImage $info = $in->getAdminThumb($image); $img = $info['markup']; } $out .= "\n\t<li><a href='./edit?file={$image->page->id},{$image->basename}" . "&modal=1&id={$this->page->id}&winwidth=$winwidth'>$img</a></li>"; } $class = $this->noThumbs ? "" : "thumbs"; if($numImageFields > 1) $class = trim("$class multifield"); $out = "\n<ul id='select_images' class='$class'>$out\n</ul>"; } /** @var InputfieldForm $form */ $form = $modules->get("InputfieldForm"); $form->action = "./"; $form->method = "get"; /** @var InputfieldPageListSelect $field */ $field = $modules->get("InputfieldPageListSelect"); $field->label = $this->_("Images on Page:") . ' ' . $this->page->get("title") . " (" . $this->page->path . ")"; // Headline for page selection, precedes current page title/url $field->description = $this->_("If you would like to select images from another page, select the page below."); // Instruction on how to select another page $field->attr('id+name', 'page_id'); $field->value = $this->page->id; $field->parent_id = 0; $field->collapsed = wireCount($images) ? Inputfield::collapsedYes : Inputfield::collapsedNo; $field->required = true; $form->append($field); // getImageFields was here $out = $form->render() . $out; if($btn) $out .= $btn->render(); return "<div id='ProcessPageEditImageSelect'>" . $out . "\n</div>"; } Add these fields to getModuleConfigInputFields method: /** @var InputfieldPageListSelect $f */ $f = $modules->get('InputfieldPageListSelect'); $f->attr('name', 'defaultPage'); $f->attr('value', @$data['defaultPage']); $f->label = $this->_('Default Page if no image fields'); $f->value = @$data['defaultPage']; $inputfields->add($f); /** @var InputfieldPageListSelect $f */ $f = $modules->get('InputfieldTextarea'); $f->attr('name', 'templateDefaultPage'); $f->attr('value', @$data['templateDefaultPage']); $f->label = $this->_('Default page by template for images if no image fields'); $f->notes = "1 pair of selectors `{template}:{page}` per line, e.g.,: `1:/home/`, or `home:1`, or `contact:template=home`"; $f->value = @$data['templateDefaultPage']; $inputfields->add($f); Copy the entire module directory into your site modules directory. Edited December 2 by hellomoto add template-specific config & tidy 1
Gideon So Posted December 1 Author Posted December 1 Hi @hellomoto Thanks for the solution. I will try your solutions later. Gideon
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now