class EntityShareTaxonomyImport in Entity Share 7
A class to import the Taxonomy.
@property EntityShareEntityImport entityShareEntity
Hierarchy
- class \EntityShareTaxonomyAbstract
- class \EntityShareTaxonomyImport
Expanded class hierarchy of EntityShareTaxonomyImport
File
- modules/
entity_share_taxonomy/ includes/ entity_share_taxonomy.import.inc, line 13 - Class for handling Taxonomy Import.
View source
class EntityShareTaxonomyImport extends EntityShareTaxonomyAbstract {
const WATCHDOG_TYPE = 'entity_share_taxonomy_import';
/**
* Manage taxonomy for the import.
*/
public function importDatas() {
// Check if the field type is managed by the module.
if (!$this
->isManagedFieldType()) {
return;
}
$entity_info = entity_get_info($this->fieldEntityType);
$term = (object) $this->fieldData;
// If there is parents, treat parent first, then continue.
$this
->manageParents($term);
// It's very important to keep the recursion there cos we have to walk
// over the tree in reverse order in order to create the term in
// sub field before the parents terms.
$this->entityShareEntity
->contentFieldWalk($term);
$this
->setLocalIds($term);
// Create or update the taxonomy term.
taxonomy_term_save($term);
// Set the tid (just created if it was not existing or
// updated if already existing).
$this->fieldData = NULL;
$this->fieldData[$entity_info['entity keys']['id']] = $term->{$entity_info['entity keys']['id']};
}
/**
* Set the exported vocabulary to the local vocabulary id.
*
* @param object $term
* Entity or sub entity to import.
*
* @return bool
* TRUE if success, FALSE otherwise.
*
* @throws EntityShareImportException
* Exception thrown in case of unexisting vocabulary locally.
*/
public static function setLocalVocabularyId($term) {
$entity_info = entity_get_info($term->entity_type);
$vocabulary_machine_name = $term->{$entity_info['entity keys']['bundle']};
$vocabulary = taxonomy_vocabulary_machine_name_load($vocabulary_machine_name);
if (!isset($vocabulary->vid)) {
watchdog(self::WATCHDOG_TYPE, 'The vocabulary %vocabulary doesn\'t exist', array(
'%vocabulary' => $vocabulary_machine_name,
), WATCHDOG_ERROR);
throw new EntityShareImportException('The vocabulary ' . $vocabulary_machine_name . ' doesn\'t exist');
}
$term->vid = $vocabulary->vid;
return TRUE;
}
/**
* Set the local ids.
*
* @param object $term
* Term to import.
*/
protected function setLocalIds($term) {
// Set the local vid (vocabulary id).
if ($term->entity_type != $this->fieldEntityType) {
self::setLocalVocabularyId($term);
}
$this->entityShareEntity
->setLocalEntityIds($term);
}
/**
* Manage the parents of a term to import.
*
* @param object $term
* Term to import.
*/
protected function manageParents($term) {
if (!empty($term->parent)) {
foreach ($term->parent as &$parent) {
if ($parent != 0) {
$parent = (object) $parent;
// The parent has parent.
if (!empty($parent->parent)) {
$this
->manageParents($parent);
}
// Import parent term.
$import = new EntityShareEntityImport($parent);
$tid = $import
->execute();
// Set the parent tid.
$parent = $tid;
}
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityShareTaxonomyAbstract:: |
protected | property | Delta of the field. | |
EntityShareTaxonomyAbstract:: |
protected | property | Entity object. | |
EntityShareTaxonomyAbstract:: |
protected | property | Entity share object. | |
EntityShareTaxonomyAbstract:: |
protected | property | Field datas. | |
EntityShareTaxonomyAbstract:: |
protected | property | Entity type of the current field. | |
EntityShareTaxonomyAbstract:: |
protected | property | Metadatas of the field. | |
EntityShareTaxonomyAbstract:: |
protected | property | Field language. | |
EntityShareTaxonomyAbstract:: |
protected | property | Field name. | |
EntityShareTaxonomyAbstract:: |
protected | property | Field type. | |
EntityShareTaxonomyAbstract:: |
protected | property | Type of field managed by the class. | |
EntityShareTaxonomyAbstract:: |
public | function | Check if the field type is managed. | |
EntityShareTaxonomyAbstract:: |
public | function | Constructor. Initialize properties. | |
EntityShareTaxonomyImport:: |
public | function | Manage taxonomy for the import. | |
EntityShareTaxonomyImport:: |
protected | function | Manage the parents of a term to import. | |
EntityShareTaxonomyImport:: |
protected | function | Set the local ids. | |
EntityShareTaxonomyImport:: |
public static | function | Set the exported vocabulary to the local vocabulary id. | |
EntityShareTaxonomyImport:: |
constant |