class FeedsTermProcessor in Feeds 8.2
Defines a taxonomy term processor.
Creates Taxonomy terms from feed items.
Plugin annotation
@Plugin(
id = "taxonomy_term",
title = @Translation("Taxonomy term processor"),
description = @Translation("Creates taxonomy terms from feed items.")
)
Hierarchy
- class \Drupal\feeds\Plugin\FeedsConfigurable
- class \Drupal\feeds\Plugin\FeedsPlugin implements FeedsSourceInterface
- class \Drupal\feeds\Plugin\FeedsProcessor
- class \Drupal\feeds\Plugin\feeds\processor\FeedsTermProcessor
- class \Drupal\feeds\Plugin\FeedsProcessor
- class \Drupal\feeds\Plugin\FeedsPlugin implements FeedsSourceInterface
Expanded class hierarchy of FeedsTermProcessor
2 string references to 'FeedsTermProcessor'
- feeds_update_7208 in ./
feeds.install - Update to use generic bundle handling.
- _feeds_feeds_plugins in ./
feeds.plugins.inc - Break out for feeds_feed_plugins().
File
- lib/
Drupal/ feeds/ Plugin/ feeds/ processor/ FeedsTermProcessor.php, line 30 - FeedsTermProcessor class.
Namespace
Drupal\feeds\Plugin\feeds\processorView 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.
*
* @todo Use entityNG.
*/
protected function newEntity(FeedsSource $source) {
return entity_create('taxonomy_term', array(
'vid' => $this
->bundle(),
'format' => isset($this->config['input_format']) ? $this->config['input_format'] : filter_fallback_format(),
))
->getBCEntity();
}
/**
* Validates a term.
*/
protected function entityValidate($term) {
if (drupal_strlen($term
->label()) == 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 ($term
->id() && ($term->parent == $term
->id() || is_array($term->parent) && in_array($term
->id(), $term->parent))) {
throw new FeedsValidationException(t("A term can't be its own child. GUID:@guid", array(
'@guid' => $term->feeds_item->guid,
)));
}
}
$term
->save();
}
/**
* Deletes a series of terms.
*/
protected function entityDeleteMultiple($tids) {
entity_delete_multiple($this
->entityType(), $tids);
}
/**
* Override parent::configDefaults().
*/
public function configDefaults() {
return array(
'vocabulary' => 0,
) + parent::configDefaults();
}
/**
* Override setTargetElement to operate on a target item that is a taxonomy term.
*/
public function setTargetElement(FeedsSource $source, $target_term, $target_element, $value) {
switch ($target_element) {
case 'parent':
if (!empty($value)) {
$terms = taxonomy_term_load_multiple_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
$query = db_select('feeds_item')
->fields('feeds_item', array(
'entity_id',
))
->condition('entity_type', $this
->entityType());
$parent_tid = $query
->condition('guid', $value)
->execute()
->fetchField();
$target_term->parent[] = $parent_tid ? $parent_tid : 0;
break;
case 'weight':
if (!empty($value)) {
$weight = intval($value);
}
else {
$weight = 0;
}
$target_term->weight = $weight;
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.'),
),
);
// Let implementers of hook_feeds_term_processor_targets() add their targets.
try {
self::loadMappers();
$entity_type = $this
->entityType();
$bundle = $this
->bundle();
drupal_alter('feeds_processor_targets', $targets, $entity_type, $bundle);
} catch (Exception $e) {
// Do nothing.
}
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') {
if ($tid = db_query("SELECT tid FROM {taxonomy_term_data} WHERE name = :name AND vid = :vid", array(
':name' => $value,
':vid' => $this
->bundle(),
))
->fetchField()) {
return $tid;
}
}
}
return 0;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | CTools export enabled status of this object. | |
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
protected | property | ||
FeedsConfigurable:: |
public static | property | ||
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 and enabled. I. e. it is defined either in code or in the database and it is enabled. | 1 |
FeedsConfigurable:: |
public | function | Implements getConfig(). | 1 |
FeedsConfigurable:: |
public static | function | Instantiate a FeedsConfigurable object. | 1 |
FeedsConfigurable:: |
public | function | Set configuration. | |
FeedsConfigurable:: |
public | function | Override magic method __get(). Make sure that $this->config goes through getConfig(). | |
FeedsConfigurable:: |
public | function | Override magic method __isset(). This is needed due to overriding __get(). | |
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 | Loads on-behalf implementations from mappers/ directory. | |
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:: |
|
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 |
Constructor. 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:: |
public | function | Remove all stored results or stored results up to a certain time for a source. | |
FeedsProcessor:: |
public | function |
Overrides parent::configForm(). Overrides FeedsConfigurable:: |
2 |
FeedsProcessor:: |
protected | function | Creates a log message for when an exception occured during import. | |
FeedsProcessor:: |
protected | function | Load an existing entity. | 2 |
FeedsProcessor:: |
protected | function | Access check for saving an enity. | 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 | Per default, don't support expiry. If processor supports expiry of imported items, return the time after which items should be removed. | 1 |
FeedsProcessor:: |
protected | function | Retrieves the MD5 hash of $entity_id from the database. | |
FeedsProcessor:: |
public | function | ||
FeedsProcessor:: |
public | function | Get mappings. | |
FeedsProcessor:: |
protected | function | Create MD5 hash of item and mappings array. | |
FeedsProcessor:: |
public | function | Counts the number of items imported by this processor. | |
FeedsProcessor:: |
protected | function | Loads existing entity information and places it on $entity->feeds_item. | |
FeedsProcessor:: |
protected | function | Execute mapping on an 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 | Utility function that iterates over a target array and retrieves all sources that are unique. | |
FeedsTermProcessor:: |
public | function |
Override parent::configDefaults(). Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
protected | function |
Deletes a series of terms. Overrides FeedsProcessor:: |
|
FeedsTermProcessor:: |
protected | function |
Implements parent::entityInfo(). 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 |
Override setTargetElement to operate on a target item that is a taxonomy term. Overrides FeedsProcessor:: |