protected function importTags($obj, $val, $record) { if ($obj->many_many('BlogCategories')) { // Optionally import into many_many created by the "ioti/blogcategories" module $holder = $this->getHolder($record); $obj->ParentID = $holder->ID; $obj->write(); // required so relation setting works // Import to BlogCategory instead of tags text field $tags = explode(',', $val); $tags = array_map('trim', $tags); $obj->BlogCategories()->removeAll(); foreach ($tags as $tag) { if (!$tag) { continue; } $cat = isset($this->_cache_categories[$tag]) ? $this->_cache_categories[$tag] : null; if (!$cat) { $cat = BlogCategory::get()->filter(array('Title' => $tag))->First(); if (!$cat) { $cat = new BlogCategory(array('Title' => $tag)); } $cat->write(); $this->_cache_categories[$tag] = $cat; } $obj->BlogCategories()->add($cat); // Not entirely accurate, since the title -> slug conversion rules // are slightly different between SS and Drupal. Should catch the majority though. $this->urlMap['category/tag-list/' . $cat->URLSegment] = $cat->getLink(); } } else { $tags = explode(',', $val); $tags = array_map('trim', $tags); $obj->Tags = implode(', ', $tags); } }