class RealisticDummyContentTermReferenceField in Realistic Dummy Content 7
Hierarchy
Expanded class hierarchy of RealisticDummyContentTermReferenceField
2 string references to 'RealisticDummyContentTermReferenceField'
File
- api/
includes/ RealisticDummyContentTaxonomyTermReferenceField.inc, line 11 - Define RealisticDummyContentTermReferenceField autoload class.
View source
class RealisticDummyContentTermReferenceField extends RealisticDummyContentField {
/**
* {@inheritdoc}
*/
function ValueFromFile_($file) {
try {
$termname = $file
->Value();
if ($termname) {
return array(
LANGUAGE_NONE => array(
array(
'tid' => $this
->GetTid($termname),
),
),
);
}
} catch (Exception $e) {
return NULL;
}
}
/**
* Returns the term id for a term which is either existing or created on the fly.
*
* Let's say an entity (node) contains a term reference to the taxonomy vocabulary
* "location", and in the realistic dummy content file structure, "Australia" is
* used for the location. If "Australia" exists as a "location", then this function
* will return its tid. If not, the term will be created, and then the tid will be
* returned.
*
* @param $name
* The string for the taxonomy term.
*
* @return
* The associated pre-existing or just-created tid.
*
* @throws
* Exception
*/
function GetTid($name) {
$vocabularies = taxonomy_get_vocabularies();
$field_info = field_info_field($this
->GetName());
$candidate_existing_terms = array();
foreach ($field_info['settings']['allowed_values'] as $vocabulary) {
$vocabulary_name = $vocabulary['vocabulary'];
foreach ($vocabularies as $vocabulary) {
if ($vocabulary->machine_name == $vocabulary_name) {
$candidate_existing_terms = array_merge($candidate_existing_terms, taxonomy_get_tree($vocabulary->vid));
}
}
}
foreach ($candidate_existing_terms as $candidate_existing_term) {
if ($candidate_existing_term->name == $name) {
return $candidate_existing_term->tid;
}
}
if (!isset($vocabulary->vid)) {
throw new Exception('Expecting the taxonomy term reference to reference at least one vocabulary');
}
$term = new stdClass();
$term->name = $name;
$term->vid = $vocabulary->vid;
taxonomy_term_save($term);
if ($term->tid) {
return $term->tid;
}
else {
throw new Exception('tid could not be determined');
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
RealisticDummyContentAttribute:: |
private | property | The entity is set on construction and is a subclass of RealisticDummyContentEntityBase. It contains information about the entity to which this field instance is attached. | |
RealisticDummyContentAttribute:: |
private | property | The name of this attribuet, for example title, picture, field_image... | |
RealisticDummyContentAttribute:: |
function | Changes this attribute by looking for data in files. | ||
RealisticDummyContentAttribute:: |
function | Given candidate files, change the value of this attribute based on one of them. | ||
RealisticDummyContentAttribute:: |
function | Returns the appropriate environment, real or testing. | ||
RealisticDummyContentAttribute:: |
function | Return a file object. | ||
RealisticDummyContentAttribute:: |
function | Gets the bundle of the associated entity. | ||
RealisticDummyContentAttribute:: |
function | Get all candidate files for a given field for this entity. | ||
RealisticDummyContentAttribute:: |
function | Getter for $this->entity | ||
RealisticDummyContentAttribute:: |
function | Get the entity type of the associated entity. | ||
RealisticDummyContentAttribute:: |
function | Get acceptable file extensions which contain data for this attribute. | 2 | |
RealisticDummyContentAttribute:: |
function | Return acceptable image file extensions. | ||
RealisticDummyContentAttribute:: |
function | Getter for $this->name | ||
RealisticDummyContentAttribute:: |
function | Return acceptable text file extensions. | ||
RealisticDummyContentAttribute:: |
function | Gets the UID of the associated entity. | ||
RealisticDummyContentAttribute:: |
function | Return an image file object if possible. | ||
RealisticDummyContentAttribute:: |
function | Returns a pseudo-random number. | ||
RealisticDummyContentAttribute:: |
function | Given a RealisticDummyContentFileGroup object, get structured property if extentions ok. | ||
RealisticDummyContentAttribute:: |
function | Given a list of files, return a value from one of them. | ||
RealisticDummyContentAttribute:: |
function | Constructor. | ||
RealisticDummyContentField:: |
function |
Returns the type of this attribute. Overrides RealisticDummyContentAttribute:: |
||
RealisticDummyContentTermReferenceField:: |
function | Returns the term id for a term which is either existing or created on the fly. | ||
RealisticDummyContentTermReferenceField:: |
function |
Given a RealisticDummyContentFileGroup object, get a structured property Overrides RealisticDummyContentAttribute:: |