/**
* Function that preProcesses data from a table prior to a store() to ensure proper tag handling
*
* @param TableInterface $table Table being processed
* @param array $newTags Array of new tags
*
* @return null
*
* @since 3.1
*/
public function preStoreProcess(TableInterface $table, $newTags = array())
{
if ($newTags != array()) {
$this->newTags = $newTags;
}
// If existing row, check to see if tags have changed.
$oldTable = clone $table;
$oldTable->reset();
$key = $oldTable->getKeyName();
$typeAlias = $this->typeAlias;
if ($oldTable->{$key} && $oldTable->load()) {
$this->oldTags = $this->getTagIds($oldTable->{$key}, $typeAlias);
}
// New items with no tags bypass this step.
if (!empty($newTags) && \is_string($newTags) || isset($newTags[0]) && $newTags[0] != '' || isset($this->oldTags)) {
if (\is_array($newTags)) {
$newTags = implode(',', $newTags);
}
// We need to process tags if the tags have changed or if we have a new row
$this->tagsChanged = empty($this->oldTags) && !empty($newTags) || !empty($this->oldTags) && $this->oldTags != $newTags || !$table->{$key};
}
}