BoldMinded acquires Ansel, support ending for all add-ons. BoldMinded acquires Ansel, support ending for all add-ons. Read More →
Support has been discontinued. Issues remain available as an archive. Support has been discontinued. Issues remain available as an archive.
Trying to get Ansel to work with Simple Cloner
#10 opened by Matt V
Description
My client really wants me to add the ability to clone an entry in ExpressionEngine. I've been working with Simple Cloner, and it's almost working properly.
Unfortunately, I've run into an issue that is preventing Ansel and Simple Cloner from working together smoothly. I'll admit right from the beginning that this is an obscure issue. But it's a potential showstopper for this functionality, so I'm hoping that you and/or the Simple Cloner folks might help me figure this out. I pinged one of them on Slack, but he thought I should start with you. I'm happy to point them to this ticket if you need me to.
Here is what triggers this issue:
I have a channel with an Ansel field. I have a simple template that calls the image URL for the Ansel field. When I create an entry (EntryA) and add an image to the Ansel field, the template displays the URL properly. When I clone the entry in Simple Cloner (EntryA-Clone), the template displays the URL properly for both entries. But if I delete EntryA-Clone, the template breaks and generates a Fatal Error. The template remains broken until I open the EntryA, remove the image(s) from the Ansel field, save the entry, and then relink the image(s) within the Ansel field. Once I do that, the template again displays the image URL properly.
Here are the error messages that I get:
Notice
Undefined offset: 149
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 306
Severity: E_NOTICE
Notice
Undefined offset: 12
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 308
Severity: E_NOTICE
Notice
Trying to get property of non-object
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 365
Severity: E_NOTICE
Notice
Trying to get property of non-object
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 365
Severity: E_NOTICE
Notice
Trying to get property of non-object
user/addons/ansel/Service/AnselImages/ImagesTag.php, line 367
Severity: E_NOTICE
Fatal error: Uncaught Error: Call to a member function getUrlSafeParam() on null in /path/to/system/user/addons/ansel/Service/AnselImages/ImagesTag.php:367 Stack trace:
#0 /path/to/system/user/addons/ansel/Service/AnselImages/ImagesTag.php(217): BuzzingPixel\Ansel\Service\AnselImages\ImagesTag->setVariablesFromRecord(Object(BuzzingPixel\Ansel\Record\Image))
#1 /path/to/system/user/addons/ansel/Controller/Field/ImagesTag.php(121): BuzzingPixel\Ansel\Service\AnselImages\ImagesTag->getVariables()
#2 /path/to/system/user/addons/ansel/ft.ansel.php(762): BuzzingPixel\Ansel\Controller\Field\ImagesTag->parse(Array, '\n\t Small: {i...')
#3 /path/to/system/ee/legacy/libraries/api/Api_channel_fields.php(409): Ansel_ft->replace_tag('{"placeholder":...', Array, '\n\t Small: {i...')
#4 /path/to/system/ee/legacy/libraries/channel_entries_parser/components/Custom_field_pair.php(203): in /path/to/system/user/addons/ansel/Service/AnselImages/ImagesTag.php on line 367
Here is the simple template I am using:
{exp:channel:entries channel="test"}
<h2>{title}</h2>
{single_image_field}
<p>URL: {img:url}</p>
{/single_image_field}
{/exp:channel:entries}
I'm using EE3.5.5, Ansel 2.0.3, and SimpleCloner 1.2.0. I've reproduced this issue on a clean install of 3.5.5 with only Ansel and Simple Cloner installed.
Any thoughts? Let me know if you have any other questions about my setup.
Replies
- TJ Draper
Replied 4/12/2017 8:33 AM, Edited 11/10/2018 10:08 AM
It sounds like Simple Cloner is duplicating the
exp_ansel_images
table rows but not creating the images themselves, but rather pointing back to the images Ansel created for the original field/entry.The way Ansel works is that the original image is uploaded to the specified directory for source images, then that image is manipulated according to the field settings and crop lasso and saved as a new image. That image that Ansel manipulated and created is considered "owned" by the originating field. As such, if the image row is deleted, or the entry or owning element is deleted, the manipulated image is deleted. In the case of Simple Cloner (from what it sounds like it is doing), if it's just duplicating the table rows in
exp_ansel_images
, then when you delete one of the image rows or entries, Ansel deletes the image because of the assumed ownership of the image. Thus that image goes missing for the other entry.The last time I looked at Simple Cloner, it looked like it was doing a lot of procedural work, direct database calls and so forth. What would be ideal would be for Simple Cloner to prep the data that Ansel expects on entry submission, then run Ansel's field type methods for the new entry. Failing that, Simple Cloner will need to duplicate the manipulated image for each image row in the containing element (entry), add it to the EE (or Assets or Treasury) file manager in the appropriate way, and then update the IDs in the duplicated
exp_ansel_images
table row to point to the new image.