smcyr / Craft-FocusPoint

A plugin for Craft CMS based on jQuery FocusPoint
MIT License
101 stars 6 forks source link

PHP Notice: Undefined Offset: 11 #24

Open bahlrbrian opened 6 years ago

bahlrbrian commented 6 years ago

When using multiple assets, if a user takes three (or more) different actions (Rearrange items, delete an item and add a new item, for example), this error appears on page save.

PHP notice
Undefined offset: 11

/var/www/examplesite/craft/plugins/focuspoint/fieldtypes/FocusPoint_FocusPointFieldType.php(48)

36         $variables["focusJs"] = "new Craft.FocusPointHelper(\"$namespacedId\");";
37 
38         return craft()->templates->render("focuspoint/input", $variables);
39     }
40 
41     public function prepValue($value)
42     {
43         $parentValues = parent::prepValue($value);
44         $i = 0;
45         $array_values = isset($this->values[spl_object_hash($this->element)]["focus-attr"]) ? array_values($this->values[spl_object_hash($this->element)]["focus-attr"]) : array();
46         foreach ($parentValues as $parentValue) {
47             if (!empty($array_values)) {
48                 $focus_attr = $array_values[$i];
49                 $focus_x = $focus_attr["data-focus-x"];
50                 $focus_y = $focus_attr["data-focus-y"];
51             } else {
52                 $focus_attr = craft()->focusPoint_focusPoint->getFocusPoint($parentValue->id, $this->model->id, $this->element->id);
53                 $focus_x = $focus_attr->focusX;
54                 $focus_y = $focus_attr->focusY;
55             }
56             $parentValue->setAttribute("focusX", $focus_x);
57             $parentValue->setAttribute("focusY", $focus_y);
58             $i++;
59         }
60         return $parentValues;
Stack Trace
#0  
–  /var/www/examplesite/craft/app/etc/web/WebApp.php(693): CApplication->handleError(8, "Undefined offset: 11", "/var/www/examplesite/craft/plugins/focuspoint/fieldtypes/Focus...", 48)
688         if (version_compare(PHP_VERSION, '7.1', '>=') && strpos($message, 'Narrowing occurred during type inference. Please file a bug report') !== false)
689         {
690             return;
691         }
692 
693         parent::handleError($code, $message, $file, $line);
694     }
695 
696     // Private Methods
697     // =========================================================================
698 
#1  
–  /var/www/examplesite/craft/plugins/focuspoint/fieldtypes/FocusPoint_FocusPointFieldType.php(48): Craft\WebApp->handleError(8, "Undefined offset: 11", "/var/www/examplesite/craft/plugins/focuspoint/fieldtypes/Focus...", 48, ...)
43         $parentValues = parent::prepValue($value);
44         $i = 0;
45         $array_values = isset($this->values[spl_object_hash($this->element)]["focus-attr"]) ? array_values($this->values[spl_object_hash($this->element)]["focus-attr"]) : array();
46         foreach ($parentValues as $parentValue) {
47             if (!empty($array_values)) {
48                 $focus_attr = $array_values[$i];
49                 $focus_x = $focus_attr["data-focus-x"];
50                 $focus_y = $focus_attr["data-focus-y"];
51             } else {
52                 $focus_attr = craft()->focusPoint_focusPoint->getFocusPoint($parentValue->id, $this->model->id, $this->element->id);
53                 $focus_x = $focus_attr->focusX;
#2  
–  /var/www/examplesite/craft/app/models/BaseElementModel.php(1008): Craft\FocusPoint_FocusPointFieldType->prepValue(array("882", "889", "688", "566", ...))
1003             $fieldType = $field->getFieldType();
1004 
1005             if ($fieldType)
1006             {
1007                 $fieldType->element = $this;
1008                 $value = $fieldType->prepValue($value);
1009             }
1010 
1011             $this->_preppedContent[$fieldHandle] = $value;
1012         }
1013 
#3  
+  /var/www/examplesite/craft/app/services/ContentService.php(403): Craft\BaseElementModel->getFieldValue("images")
#4  
+  /var/www/examplesite/craft/app/services/ContentService.php(154): Craft\ContentService->_updateSearchIndexes(Craft\EntryModel, Craft\ContentModel, Craft\FieldLayoutModel, null, ...)
#5  
+  /var/www/examplesite/craft/app/services/ElementsService.php(1426): Craft\ContentService->saveContent(Craft\EntryModel, false, true)
#6  
+  /var/www/examplesite/craft/app/services/EntriesService.php(176): Craft\ElementsService->saveElement(Craft\EntryModel)
#7  
+  /var/www/examplesite/craft/app/controllers/EntriesController.php(462): Craft\EntriesService->saveEntry(Craft\EntryModel)
#8  
+  /var/www/examplesite/craft/app/framework/web/actions/CInlineAction.php(49): Craft\EntriesController->actionSaveEntry()
#9  
+  /var/www/examplesite/craft/app/framework/web/CController.php(308): CInlineAction->runWithParams(array("p" => "admin/entries/portfolio/572-harrison-residence-1"))
#10 
+  /var/www/examplesite/craft/app/framework/web/CController.php(286): CController->runAction(CInlineAction)
#11 
+  /var/www/examplesite/craft/app/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array())
#12 
+  /var/www/examplesite/craft/app/framework/web/CWebApplication.php(282): CController->run("saveEntry")
#13 
+  /var/www/examplesite/craft/app/etc/web/WebApp.php(823): CWebApplication->runController("entries/saveEntry")
#14 
+  /var/www/examplesite/craft/app/etc/web/WebApp.php(287): Craft\WebApp->_processActionRequest()
#15 
+  /var/www/examplesite/craft/app/framework/base/CApplication.php(185): Craft\WebApp->processRequest()
#16 
+  /var/www/examplesite/craft/app/index.php(62): CApplication->run()
#17 
+  /var/www/examplesite/public/index.php(19): require_once("/var/www/examplesite/craft/app/index.php")
2017-12-15 20:51:48 Apache/2.4.18 (Ubuntu) / Craft CMS 2.6.3000
smcyr commented 6 years ago

Let me know if 1.1.8 fix the issue, thanks