contrib modules security updates
This commit is contained in:
@@ -22,6 +22,7 @@ class FeedsTermProcessor extends FeedsProcessor {
|
||||
protected function entityInfo() {
|
||||
$info = parent::entityInfo();
|
||||
$info['label plural'] = t('Terms');
|
||||
$info['bundle name'] = t('Vocabulary');
|
||||
return $info;
|
||||
}
|
||||
|
||||
@@ -30,25 +31,35 @@ class FeedsTermProcessor extends FeedsProcessor {
|
||||
*/
|
||||
protected function newEntity(FeedsSource $source) {
|
||||
$vocabulary = $this->vocabulary();
|
||||
$term = new stdClass();
|
||||
$term = parent::newEntity($source);
|
||||
$term->vid = $vocabulary->vid;
|
||||
$term->vocabulary_machine_name = $vocabulary->machine_name;
|
||||
$term->format = isset($this->config['input_format']) ? $this->config['input_format'] : filter_fallback_format();
|
||||
|
||||
return $term;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads an existing term.
|
||||
* Load an existing entity.
|
||||
*/
|
||||
protected function entityLoad(FeedsSource $source, $tid) {
|
||||
return taxonomy_term_load($tid);
|
||||
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) {
|
||||
if (empty($term->name)) {
|
||||
parent::entityValidate($term);
|
||||
|
||||
if (drupal_strlen($term->name) == 0) {
|
||||
throw new FeedsValidationException(t('Term name missing.'));
|
||||
}
|
||||
}
|
||||
@@ -90,37 +101,11 @@ class FeedsTermProcessor extends FeedsProcessor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent::configForm().
|
||||
* Overrides parent::setTargetElement().
|
||||
*
|
||||
* Operate on a target item that is a taxonomy term.
|
||||
*/
|
||||
public function configForm(&$form_state) {
|
||||
$options = array(0 => t('Select a vocabulary'));
|
||||
foreach (taxonomy_get_vocabularies() as $vocab) {
|
||||
$options[$vocab->machine_name] = $vocab->name;
|
||||
}
|
||||
$form = parent::configForm($form_state);
|
||||
$form['vocabulary'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Import to vocabulary'),
|
||||
'#description' => t('Choose the vocabulary to import into. <strong>CAUTION:</strong> when deleting terms through the "Delete items" tab, Feeds will delete <em>all</em> terms from this vocabulary.'),
|
||||
'#options' => $options,
|
||||
'#default_value' => $this->config['vocabulary'],
|
||||
);
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Override parent::configFormValidate().
|
||||
*/
|
||||
public function configFormValidate(&$values) {
|
||||
if (empty($values['vocabulary'])) {
|
||||
form_set_error('vocabulary', t('Choose a vocabulary'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Override setTargetElement to operate on a target item that is a taxonomy term.
|
||||
*/
|
||||
public function setTargetElement(FeedsSource $source, $target_term, $target_element, $value) {
|
||||
public function setTargetElement(FeedsSource $source, $target_term, $target_element, $value, array $mapping = array()) {
|
||||
switch ($target_element) {
|
||||
case 'parent':
|
||||
if (!empty($value)) {
|
||||
@@ -142,15 +127,26 @@ class FeedsTermProcessor extends FeedsProcessor {
|
||||
$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());
|
||||
$parent_tid = $query->condition('guid', $value)->execute()->fetchField();
|
||||
$target_term->parent[] = ($parent_tid) ? $parent_tid : 0;
|
||||
|
||||
$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);
|
||||
@@ -160,6 +156,20 @@ class FeedsTermProcessor extends FeedsProcessor {
|
||||
}
|
||||
$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;
|
||||
@@ -195,19 +205,13 @@ class FeedsTermProcessor extends FeedsProcessor {
|
||||
'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'),
|
||||
),
|
||||
);
|
||||
|
||||
// Let implementers of hook_feeds_term_processor_targets() add their targets.
|
||||
try {
|
||||
self::loadMappers();
|
||||
$entity_type = $this->entityType();
|
||||
$bundle = $this->vocabulary()->machine_name;
|
||||
drupal_alter('feeds_processor_targets', $targets, $entity_type, $bundle);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
// Do nothing.
|
||||
}
|
||||
$this->getHookTargets($targets);
|
||||
|
||||
return $targets;
|
||||
}
|
||||
|
||||
@@ -235,11 +239,19 @@ class FeedsTermProcessor extends FeedsProcessor {
|
||||
* Return vocabulary to map to.
|
||||
*/
|
||||
public function vocabulary() {
|
||||
if (isset($this->config['vocabulary'])) {
|
||||
if ($vocabulary = taxonomy_vocabulary_machine_name_load($this->config['vocabulary'])) {
|
||||
return $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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user