class CFNodeSubject in Changed Fields API 7.2
Same name and namespace in other branches
- 7.3 src/CFNodeSubject.php \CFNodeSubject
- 7 includes/changed_fields.core.inc \CFNodeSubject
Class CFNodeSubject.
Hierarchy
- class \CFNodeSubject implements CFSubjectInterface
Expanded class hierarchy of CFNodeSubject
File
- includes/
changed_fields.core.inc, line 107 - File contains core classes and interfaces.
View source
class CFNodeSubject implements CFSubjectInterface {
/**
* Node object.
*
* @var \stdClass
*/
private $node;
/**
* Info array.
*
* Array contains mapping for content types and fields to watch.
*
* @var array
*/
private $info;
/**
* Field comparator object.
*
* @var CFDefaultFieldComparator
*/
private $fieldComparator;
/**
* Array contains all registered observers.
*
* @var array
*/
private $observers;
/**
* Node subject constructor.
*
* @param \stdClass $node
* Node object.
* @param array $info
* Array contains mapping for content types and fields to watch.
* @param CFDefaultFieldComparator $fieldComparator
* Field comparator object.
*/
public function __construct(\stdClass $node, array $info, CFDefaultFieldComparator $fieldComparator) {
$this->node = $node;
$this->info = $info;
$this->fieldComparator = $fieldComparator;
}
/**
* {@inheritdoc}
*/
public function addObserver(CFObserverInterface $observer) {
$this->observers[$observer
->getId()] = $observer;
}
/**
* {@inheritdoc}
*/
public function removeObserver(CFObserverInterface $observer) {
unset($this->observers[$observer
->getId()]);
}
/**
* {@inheritdoc}
*/
public function checkNodeFields() {
foreach ($this->info as $nodeType => $fields) {
if (isset($this->node->original) && $this->node->type == $nodeType) {
$this->node->changed_fields = array();
foreach ($fields as $fieldName) {
if ($fieldName == 'title') {
$oldValue = $this->node->original->{$fieldName};
$newValue = $this->node->{$fieldName};
$fieldInfo['field_base'] = array(
'type' => 'title',
);
}
else {
$oldValue = field_get_items('node', $this->node->original, $fieldName);
$newValue = field_get_items('node', $this->node, $fieldName);
$fieldInfo['field_base'] = field_info_field($fieldName);
}
$fieldInfo['field_instance'] = field_info_instance('node', $fieldName, $nodeType);
$result = $this->fieldComparator
->runFieldComparison($fieldInfo, $oldValue, $newValue);
if (is_array($result)) {
$this->node->changed_fields[$fieldName] = $result;
}
}
if (!empty($this->node->changed_fields)) {
foreach ($this->observers as $observer) {
$observer
->update($this);
}
}
}
}
}
/**
* {@inheritdoc}
*/
public function getNode() {
return $this->node;
}
/**
* {@inheritdoc}
*/
public function getChangedFields() {
return $this->node->changed_fields;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CFNodeSubject:: |
private | property | Field comparator object. | |
CFNodeSubject:: |
private | property | Info array. | |
CFNodeSubject:: |
private | property | Node object. | |
CFNodeSubject:: |
private | property | Array contains all registered observers. | |
CFNodeSubject:: |
public | function |
Add observer to list. Overrides CFSubjectInterface:: |
|
CFNodeSubject:: |
public | function |
Notify all registered observers if needed. Overrides CFSubjectInterface:: |
|
CFNodeSubject:: |
public | function |
Returns changed fields. Overrides CFSubjectInterface:: |
|
CFNodeSubject:: |
public | function |
Returns node object. Overrides CFSubjectInterface:: |
|
CFNodeSubject:: |
public | function |
Remove observer from list. Overrides CFSubjectInterface:: |
|
CFNodeSubject:: |
public | function | Node subject constructor. |