class FeedsTermProcessor in Feeds 7.2
Same name and namespace in other branches
- 6 plugins/FeedsTermProcessor.inc \FeedsTermProcessor
- 7 plugins/FeedsTermProcessor.inc \FeedsTermProcessor
Feeds processor plugin. Create taxonomy terms from feed items.
Hierarchy
- class \FeedsConfigurable
- class \FeedsPlugin implements FeedsSourceInterface
- class \FeedsProcessor
- class \FeedsTermProcessor
- class \FeedsProcessor
- class \FeedsPlugin implements FeedsSourceInterface
Expanded class hierarchy of FeedsTermProcessor
11 string references to 'FeedsTermProcessor'
- FeedsCSVtoTermsTest::setUp in tests/
feeds_processor_term.test - Set up test.
- FeedsCSVtoTermsTest::test in tests/
feeds_processor_term.test - Test term creation, refreshing/deleting feeds and feed items.
- FeedsCSVtoTermsTest::testParentTargetByGUID in tests/
feeds_processor_term.test - Tests that terms mapped to their parent by GUID are from the same vocabulary.
- FeedsCSVtoTermsTest::testParentTargetByName in tests/
feeds_processor_term.test - Tests that terms mapped to their parent by GUID are from the same vocabulary.
- FeedsCSVtoTermsTest::testReplaceTerms in tests/
feeds_processor_term.test - Test replacing terms on subsequent imports.
File
- plugins/
FeedsTermProcessor.inc, line 11 - FeedsTermProcessor class.
View source
class FeedsTermProcessor extends FeedsProcessor {
/**
* Define entity type.
*/
public function entityType() {
return 'taxonomy_term';
}
/**
* Implements parent::entityInfo().
*/
protected function entityInfo() {
$info = parent::entityInfo();
$info['label plural'] = t('Terms');
$info['bundle name'] = t('Vocabulary');
return $info;
}
/**
* Creates a new term in memory and returns it.
*/
protected function newEntity(FeedsSource $source) {
$vocabulary = $this
->vocabulary();
$term = parent::newEntity($source);
$term->vid = $vocabulary->vid;
$term->vocabulary_machine_name = $vocabulary->machine_name;
return $term;
}
/**
* Load an existing entity.
*/
protected function entityLoad(FeedsSource $source, $entity_id) {
$entity = parent::entityLoad($source, $entity_id);
// Avoid missing bundle errors when term has been loaded directly from db.
if (empty($entity->vocabulary_machine_name) && !empty($entity->vid)) {
$vocabulary = taxonomy_vocabulary_load($entity->vid);
$entity->vocabulary_machine_name = $vocabulary ? $vocabulary->machine_name : NULL;
}
return $entity;
}
/**
* Validates a term.
*/
protected function entityValidate($term, FeedsSource $source = NULL) {
parent::entityValidate($term);
if (drupal_strlen($term->name) == 0) {
throw new FeedsValidationException(t('Term name missing.'));
}
}
/**
* Saves a term.
*
* We de-array parent fields with only one item.
* This stops leftandright module from freaking out.
*/
protected function entitySave($term) {
if (isset($term->parent)) {
if (is_array($term->parent) && count($term->parent) == 1) {
$term->parent = reset($term->parent);
}
if (isset($term->tid) && ($term->parent == $term->tid || is_array($term->parent) && in_array($term->tid, $term->parent))) {
throw new FeedsValidationException(t("A term can't be its own child. GUID:@guid", array(
'@guid' => $term->feeds_item->guid,
)));
}
}
taxonomy_term_save($term);
}
/**
* Deletes a series of terms.
*/
protected function entityDeleteMultiple($tids) {
foreach ($tids as $tid) {
taxonomy_term_delete($tid);
}
}
/**
* Override parent::configDefaults().
*/
public function configDefaults() {
return array(
'vocabulary' => 0,
) + parent::configDefaults();
}
/**
* Overrides parent::setTargetElement().
*
* Operate on a target item that is a taxonomy term.
*/
public function setTargetElement(FeedsSource $source, $target_term, $target_element, $value, array $mapping = array()) {
switch ($target_element) {
case 'parent':
if (!empty($value)) {
$terms = taxonomy_get_term_by_name($value);
$parent_tid = '';
foreach ($terms as $term) {
if ($term->vid == $target_term->vid) {
$parent_tid = $term->tid;
}
}
if (!empty($parent_tid)) {
$target_term->parent[] = $parent_tid;
}
else {
$target_term->parent[] = 0;
}
}
else {
$target_term->parent[] = 0;
}
break;
case 'parentguid':
// Value is parent_guid field value.
$parent_tid = 0;
$query = db_select('feeds_item')
->fields('feeds_item', array(
'entity_id',
))
->condition('entity_type', $this
->entityType());
$term_ids = array_keys($query
->condition('guid', $value)
->execute()
->fetchAllAssoc('entity_id'));
if (!empty($term_ids)) {
$terms = entity_load($this
->entityType(), $term_ids);
foreach ($terms as $term) {
if ($term->vid == $target_term->vid) {
$parent_tid = $term->tid;
break;
}
}
}
$target_term->parent[] = $parent_tid;
break;
case 'weight':
if (!empty($value)) {
$weight = intval($value);
}
else {
$weight = 0;
}
$target_term->weight = $weight;
break;
case 'description':
if (!empty($mapping['format'])) {
$target_term->format = $mapping['format'];
}
elseif (!empty($this->config['input_format'])) {
$target_term->format = $this->config['input_format'];
}
else {
$target_term->format = filter_fallback_format();
}
$target_term->description = $value;
break;
default:
parent::setTargetElement($source, $target_term, $target_element, $value);
break;
}
}
/**
* Return available mapping targets.
*/
public function getMappingTargets() {
$targets = parent::getMappingTargets();
$targets += array(
'name' => array(
'name' => t('Term name'),
'description' => t('Name of the taxonomy term.'),
'optional_unique' => TRUE,
),
'parent' => array(
'name' => t('Parent: Term name'),
'description' => t('The name of the parent taxonomy term.'),
'optional_unique' => TRUE,
),
'parentguid' => array(
'name' => t('Parent: GUID'),
'description' => t('The GUID of the parent taxonomy term.'),
'optional_unique' => TRUE,
),
'weight' => array(
'name' => t('Term weight'),
'description' => t('Weight of the taxonomy term.'),
'optional_unique' => TRUE,
),
'description' => array(
'name' => t('Term description'),
'description' => t('Description of the taxonomy term.'),
'summary_callbacks' => array(
'text_feeds_summary_callback',
),
'form_callbacks' => array(
'text_feeds_form_callback',
),
),
);
$this
->getHookTargets($targets);
return $targets;
}
/**
* Get id of an existing feed item term if available.
*/
protected function existingEntityId(FeedsSource $source, FeedsParserResult $result) {
if ($tid = parent::existingEntityId($source, $result)) {
return $tid;
}
// The only possible unique target is name.
foreach ($this
->uniqueTargets($source, $result) as $target => $value) {
if ($target == 'name') {
$vocabulary = $this
->vocabulary();
if ($tid = db_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name AND vid = :vid", array(
':name' => $value,
':vid' => $vocabulary->vid,
))
->fetchField()) {
return $tid;
}
}
}
return 0;
}
/**
* Return vocabulary to map to.
*/
public function vocabulary() {
if ($vocabulary = taxonomy_vocabulary_machine_name_load($this
->bundle())) {
return $vocabulary;
}
throw new Exception(t('No vocabulary defined for Taxonomy Term processor.'));
}
/**
* Overrides FeedsProcessor::dependencies().
*/
public function dependencies() {
$dependencies = parent::dependencies();
$dependencies['taxonomy'] = 'taxonomy';
return $dependencies;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsConfigurable:: |
protected | property | Holds the actual configuration information. | |
FeedsConfigurable:: |
protected | property | CTools export enabled status of this object. | |
FeedsConfigurable:: |
protected | property | CTools export type of this object. | |
FeedsConfigurable:: |
protected | property | An unique identifier for the configuration. | |
FeedsConfigurable:: |
public | function | Similar to setConfig but adds to existing configuration. | |
FeedsConfigurable:: |
public | function | Submission handler for configForm(). | 2 |
FeedsConfigurable:: |
public | function | Validation handler for configForm(). | 3 |
FeedsConfigurable:: |
public | function | Copy a configuration. | 1 |
FeedsConfigurable:: |
public | function | Determine whether this object is persistent. | 1 |
FeedsConfigurable:: |
public | function | Determines whether this object is persistent and enabled. | 1 |
FeedsConfigurable:: |
public | function | Implements getConfig(). | 1 |
FeedsConfigurable:: |
public | function | Returns whether or not the configurable has a config form. | |
FeedsConfigurable:: |
public | function | Determine whether this object is enabled. | |
FeedsConfigurable:: |
public | function | Set configuration. | |
FeedsConfigurable:: |
public | function | Overrides magic method __get(). | |
FeedsConfigurable:: |
public | function | Override magic method __isset(). This is needed due to overriding __get(). | |
FeedsPlugin:: |
protected | property | The plugin definition. | |
FeedsPlugin:: |
public static | function | Get all available plugins. | |
FeedsPlugin:: |
public static | function | Gets all available plugins of a particular type. | |
FeedsPlugin:: |
public static | function | Determines whether given plugin is derived from given base plugin. | |
FeedsPlugin:: |
public | function |
Returns TRUE if $this->sourceForm() returns a form. Overrides FeedsSourceInterface:: |
|
FeedsPlugin:: |
public static | function |
Instantiates a FeedsPlugin object. Overrides FeedsConfigurable:: |
|
FeedsPlugin:: |
public static | function | Loads on-behalf implementations from mappers/ directory. | |
FeedsPlugin:: |
public | function | Returns the plugin definition. | |
FeedsPlugin:: |
public | function |
Save changes to the configuration of this object.
Delegate saving to parent (= Feed) which will collect
information from this object by way of getConfig() and store it. Overrides FeedsConfigurable:: |
1 |
FeedsPlugin:: |
protected | function | Sets the plugin definition. | |
FeedsPlugin:: |
public | function |
Implements FeedsSourceInterface::sourceDefaults(). Overrides FeedsSourceInterface:: |
1 |
FeedsPlugin:: |
public | function |
A source is being deleted. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public | function |
Callback methods, exposes source form. Overrides FeedsSourceInterface:: |
3 |
FeedsPlugin:: |
public | function |
Validation handler for sourceForm. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public | function |
A source is being saved. Overrides FeedsSourceInterface:: |
2 |
FeedsPlugin:: |
public static | function | Determines the type of a plugin. | |
FeedsPlugin:: |
protected | function |
Constructs a FeedsPlugin object. Overrides FeedsConfigurable:: |
|
FeedsProcessor:: |
public | function | Bundle type this processor operates on. | |
FeedsProcessor:: |
public | function | Provides a list of bundle options for use in select lists. | |
FeedsProcessor:: |
protected | function | Deletes entities which were not found during processing. | 2 |
FeedsProcessor:: |
public | function | Removes all imported items for a source. | |
FeedsProcessor:: |
public | function |
Returns configuration form for this object. Overrides FeedsConfigurable:: |
2 |
FeedsProcessor:: |
protected | function | Creates a log entry for when an exception occurred during import. | |
FeedsProcessor:: |
protected | function | DEPRECATED: Creates a log message for exceptions during import. | |
FeedsProcessor:: |
protected | function | Returns the current language for entities. | |
FeedsProcessor:: |
protected | function | Access check for saving an entity. | 1 |
FeedsProcessor:: |
public | function | Deletes feed items older than REQUEST_TIME - $time. | |
FeedsProcessor:: |
protected | function | Returns a database query used to select entities to expire. | 1 |
FeedsProcessor:: |
public | function | Returns the time in seconds after which items should be removed. | 1 |
FeedsProcessor:: |
protected | function | Returns a string representation of an object or array for log messages. | |
FeedsProcessor:: |
protected | function | Returns a statically cached version of the source mappings. | |
FeedsProcessor:: |
protected | function | Returns a statically cached version of the target mappings. | |
FeedsProcessor:: |
protected | function | Retrieves the MD5 hash of $entity_id from the database. | |
FeedsProcessor:: |
protected | function | Allows other modules to expose targets. | |
FeedsProcessor:: |
public | function | Report number of items that can be processed per call. | |
FeedsProcessor:: |
public | function | Get mappings. | |
FeedsProcessor:: |
protected | function | Returns the values from the parser, or callback. | |
FeedsProcessor:: |
protected | function | Create MD5 hash of item and mappings array. | |
FeedsProcessor:: |
protected | function | Initializes the list of entities to remove. | 1 |
FeedsProcessor:: |
public | function | Counts the number of items imported by this processor. | |
FeedsProcessor:: |
public | function | Provides a list of languages available on the site. | 1 |
FeedsProcessor:: |
protected | function | Loads existing entity information and places it on $entity->feeds_item. | |
FeedsProcessor:: |
protected | function | Execute mapping on an item. | 1 |
FeedsProcessor:: |
protected | function | Maps values onto the target item. | |
FeedsProcessor:: |
protected | function | Adds Feeds specific information on $entity->feeds_item. | |
FeedsProcessor:: |
public | function |
Implements FeedsPlugin::pluginType(). Overrides FeedsPlugin:: |
|
FeedsProcessor:: |
public | function | Process the result of the parsing stage. | |
FeedsProcessor:: |
protected | function | Returns all mapping targets that are marked as unique. | |
FeedsProcessor:: |
protected | function | Helper function to unravel error messages hidden in a FieldValidationException. | |
FeedsProcessor:: |
public | function |
Validates the configuration. Overrides FeedsConfigurable:: |
|
FeedsProcessor:: |
protected | function | Validates fields of an entity. | |
FeedsTermProcessor:: |
public | function |
Override parent::configDefaults(). Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
public | function |
Overrides FeedsProcessor::dependencies(). Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
protected | function |
Deletes a series of terms. Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
protected | function |
Implements parent::entityInfo(). Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
protected | function |
Load an existing entity. Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
protected | function |
Saves a term. Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
public | function |
Define entity type. Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
protected | function |
Validates a term. Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
protected | function |
Get id of an existing feed item term if available. Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
public | function |
Return available mapping targets. Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
protected | function |
Creates a new term in memory and returns it. Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
public | function |
Overrides parent::setTargetElement(). Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
public | function | Return vocabulary to map to. |