class CFNodeSubject in Changed Fields API 7
Same name and namespace in other branches
- 7.3 src/CFNodeSubject.php \CFNodeSubject
- 7.2 includes/changed_fields.core.inc \CFNodeSubject
Class CFNodeSubject.
Hierarchy
- class \CFNodeSubject implements CFSubject
Expanded class hierarchy of CFNodeSubject
File
- includes/
changed_fields.core.inc, line 82 - changed_fields.core.inc file.
View source
class CFNodeSubject implements CFSubject {
/**
* @var stdClass
*/
private $node;
/**
* @var array
*/
private $info;
/**
* @var array
*/
private $changedFields;
/**
* @var CFDefaultFieldComparator
*/
private $fieldComparator;
/**
* @var array
*/
private $observers;
/**
* @param stdClass $node
* @param array $info
* @param CFDefaultFieldComparator $fieldComparator
*/
public function __construct(stdClass $node, array $info, CFDefaultFieldComparator $fieldComparator) {
$this->node = $node;
$this->info = $info;
$this->changedFields = array();
$this->fieldComparator = $fieldComparator;
}
/**
* {@inheritdoc}
*/
public function addObserver(CFObserver $observer) {
$this->observers[$observer
->getId()] = $observer;
}
/**
* {@inheritdoc}
*/
public function removeObserver(CFObserver $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) {
$changedFields = array();
foreach ($fields as $fieldName) {
if ($fieldName == 'title') {
$oldValue = $this->node->original->{$fieldName};
$newValue = $this->node->{$fieldName};
$fieldInfo = array(
'type' => 'title',
);
}
else {
$oldValue = field_get_items('node', $this->node->original, $fieldName);
$newValue = field_get_items('node', $this->node, $fieldName);
$fieldInfo = field_info_field($fieldName);
}
$result = $this->fieldComparator
->runFieldComparison($fieldInfo, $oldValue, $newValue);
if (is_array($result)) {
$changedFields[$fieldName] = $result;
}
}
if (!empty($changedFields)) {
$this->changedFields = $changedFields;
foreach ($this->observers as $observer) {
$observer
->update($this);
}
}
}
}
}
/**
* {@inheritdoc}
*/
public function getNode() {
return $this->node;
}
/**
* {@inheritdoc}
*/
public function getChangedFields() {
return $this->changedFields;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CFNodeSubject:: |
private | property | ||
CFNodeSubject:: |
private | property | ||
CFNodeSubject:: |
private | property | ||
CFNodeSubject:: |
private | property | ||
CFNodeSubject:: |
private | property | ||
CFNodeSubject:: |
public | function |
Add observer to list. Overrides CFSubject:: |
|
CFNodeSubject:: |
public | function |
Notify all registered observers if needed. Overrides CFSubject:: |
|
CFNodeSubject:: |
public | function |
Returns changed fields. Overrides CFSubject:: |
|
CFNodeSubject:: |
public | function |
Returns node object. Overrides CFSubject:: |
|
CFNodeSubject:: |
public | function |
Remove observer from list. Overrides CFSubject:: |
|
CFNodeSubject:: |
public | function |