<p>I was running into this same issue where all of the focal points were being lost when saving entries from the command line. I wrote a pull request to fix the issue that was recently merged, so this should hopefully no longer be an issue as of version <a href="https://github.com/smcyr/Craft-FocusPoint/commit/ed063821a3009c9a0f66e1bbc9ca5fa3f410e007" rel="nofollow noreferrer">1.1.7</a>. :)</p>

CC BY-SA 3.0
2017-10-01T03:43:31.123Z
2017-10-01T03:43:31.123Z
Aaron Waldon
<p>I recently had the same problem when saving entries in my plugin. I only wanted to update an entry field that had nothing to do with the focus image and save that entry. Turned out the focus image lost its value (I think it happens only when the field is required).</p>

<p>I solved it by getting the value of the focusImageField and just re-set it when saving the entry:</p>

<pre><code>$entry-&gt;setContentFromPost(array(
// imageWithFocusPoint is required but returns empty,
// so set it with same value it allready had
   'imageWithFocusPoint' =&gt; $entry-&gt;imageWithFocusPoint-&gt;ids(),
));

craft()-&gt;entries-&gt;saveEntry($entry);
</code></pre>

<p>More info that helped me here: <a href="http://goo.gl/soli9T" rel="nofollow">http://goo.gl/soli9T</a></p>

<p>Another solution (and the one I used but maybe less of an option for you) is to disable validation on the entry save. By using:</p>

<pre><code>craft()-&gt;content-&gt;saveContent($entry, false);
</code></pre>

<p>instead of saveEntry. The "false" as second parameter means it will not validate the entry which is not always necessary.</p>

CC BY-SA 3.0
2016-06-07T08:29:16.820Z
2016-06-07T08:29:16.820Z
Tom De Smet
<p>I've implemented a plugin for synchronizing an external Database into my Craft project which also includes images.</p>

<p>Those images have a focuspointer but i lose the focuspointer onSaveEntry by my plugin. 
(I'm using the <a href="https://github.com/smcyr/Craft-FocusPoint" rel="nofollow">Focuspointer Plugin</a>)</p>

<p>Note: I only lose the focuspointer when updating an entry by my plugin, updating an entry by control panel works fine.</p>

<p>This is the code from the focuspointer plugin where the focuspoint get's deleted:</p>

<pre><code>public function onAfterElementSave()
{
    craft()-&gt;focusPoint_focusPoint-&gt;deleteFocusPointRecordsByFieldIdAndSourceId(
        $this-&gt;model-&gt;id,
        $this-&gt;element-&gt;id
    );

    $hash = spl_object_hash($this-&gt;element);

    $value = isset($this-&gt;values[$hash]) ? $this-&gt;values[$hash] : null;

    if ($value &amp;&amp; isset($value["focus-attr"])) {
        $i = 0;
        foreach ($value["focus-attr"] as $focus_attr) {
            craft()-&gt;focusPoint_focusPoint-&gt;createOrUpdateFocusPoint(
                $focus_attr["data-focus-x"],
                $focus_attr["data-focus-y"],
                $value[$i],
                $this-&gt;model-&gt;id,
                $this-&gt;element-&gt;id
            );
            $i++;
        }
    }

    parent::onAfterElementSave();
}
</code></pre>

<p>How can I prevent the loss of the focus point onSaveEntry by my plugin?</p>

<plugin-development><saveentry>
Losing focuspoint on saveEntry by plugin
# Losing focuspoint on saveEntry by plugin

(Asked by: username_0 on 2016-06-07)

I've implemented a plugin for synchronizing an external Database into my Craft project which also includes images.
Those images have a focuspointer but i lose the focuspointer onSaveEntry by my plugin. 
(I'm using the Focuspointer Plugin)
Note: I only lose the focuspointer when updating an entry by my plugin, updating an entry by control panel works fine.
This is the code from the focuspointer plugin where the focuspoint get's deleted:
public function onAfterElementSave()
{
    craft()->focusPoint_focusPoint->deleteFocusPointRecordsByFieldIdAndSourceId(
        $this->model->id,
        $this->element->id
    );

    $hash = spl_object_hash($this->element);

    $value = isset($this->values[$hash]) ? $this->values[$hash] : null;

    if ($value && isset($value["focus-attr"])) {
        $i = 0;
        foreach ($value["focus-attr"] as $focus_attr) {
            craft()->focusPoint_focusPoint->createOrUpdateFocusPoint(
                $focus_attr["data-focus-x"],
                $focus_attr["data-focus-y"],
                $value[$i],
                $this->model->id,
                $this->element->id
            );
            $i++;
        }
    }

    parent::onAfterElementSave();
}

How can I prevent the loss of the focus point onSaveEntry by my plugin?

**Tags:** plugin-development, saveentry

---

## 2 answers

### Answer by username_1 on 2017-10-01. Score: 1

I was running into this same issue where all of the focal points were being lost when saving entries from the command line. I wrote a pull request to fix the issue that was recently merged, so this should hopefully no longer be an issue as of version [1.1.7](https://github.com/smcyr/Craft-FocusPoint/commit/ed063821a3009c9a0f66e1bbc9ca5fa3f410e007). :)


---

### Answer by username_2 on 2016-06-07. Score: 1

I recently had the same problem when saving entries in my plugin. I only wanted to update an entry field that had nothing to do with the focus image and save that entry. Turned out the focus image lost its value (I think it happens only when the field is required).
I solved it by getting the value of the focusImageField and just re-set it when saving the entry:
$entry->setContentFromPost(array(
// imageWithFocusPoint is required but returns empty,
// so set it with same value it allready had
   'imageWithFocusPoint' => $entry->imageWithFocusPoint->ids(),
));

craft()->entries->saveEntry($entry);

More info that helped me here: http://goo.gl/soli9T
Another solution (and the one I used but maybe less of an option for you) is to disable validation on the entry save. By using:
craft()->content->saveContent($entry, false);

instead of saveEntry. The "false" as second parameter means it will not validate the entry which is not always necessary.


---

