class NodeSaveHandler in Services Client 7.2
Adds extra logic for saving remote nodes.
Hierarchy
- class \ServicesClientPlugin implements ServicesClientConfigurableInterface
- class \EventHandler
- class \EntitySaveHandler
- class \NodeSaveHandler
- class \EntitySaveHandler
- class \EventHandler
Expanded class hierarchy of NodeSaveHandler
2 string references to 'NodeSaveHandler'
- services_client_migrate_hook in ./
services_client.legacy.inc - Migrate old hook with mapping to new system.
- services_client_services_client_event_handler in ./
services_client.plugins.inc - List availalable event handler plugins.
File
- include/
event.inc, line 1125
View source
class NodeSaveHandler extends EntitySaveHandler {
/**
* Load default plugin configuration.
*/
public function getDefaultConfiguration() {
$conf = parent::getDefaultConfiguration();
$conf += array(
'node_type' => '',
'node_author' => 'load_remote',
'node_author_value' => 0,
'node_author_load_remote' => 0,
);
return $conf;
}
/**
* Configuration form.
*/
public function configForm(&$form, &$form_state) {
parent::configForm($form, $form_state);
$form['node'] = array(
'#type' => 'fieldset',
'#title' => t('Node configuration'),
'#tree' => FALSE,
);
$form['node']['node_type'] = array(
'#type' => 'textfield',
'#title' => t('Node type'),
'#description' => t('Override node type which will be sent to remote site'),
'#default_value' => $this->config['node_type'],
);
$form['node']['node_author'] = array(
'#type' => 'select',
'#title' => t('Node author'),
'#description' => t('How to set remote node author'),
'#default_value' => $this->config['node_author'],
'#options' => array(
'value' => t('Hardcode value for each node'),
'load_remote' => t('Map current user to remote site'),
'no_value' => t("Don't send any author value"),
),
);
$form['node']['node_author_value'] = array(
'#type' => 'textfield',
'#title' => t('Hardcoded author value'),
'#description' => t('Enter remote site UID'),
'#default_value' => $this->config['node_author_value'],
'#states' => array(
'visible' => array(
':input[name="node_author"]' => array(
'value' => 'value',
),
),
),
);
$form['node']['node_author_load_remote'] = array(
'#type' => 'textfield',
'#title' => t('Default author value'),
'#description' => t('Enter remote site UID which will be used if mapping to remote uid will fail.'),
'#default_value' => $this->config['node_author_load_remote'],
'#states' => array(
'visible' => array(
':input[name="node_author"]' => array(
'value' => 'load_remote',
),
),
),
);
}
/**
* Save configuration.
*/
public function configFormSubmit(&$form, &$form_state) {
parent::configFormSubmit($form, $form_state);
$this->config['node_type'] = $form_state['values']['node_type'];
$this->config['node_author'] = $form_state['values']['node_author'];
$this->config['node_author_value'] = $form_state['values']['node_author_value'];
$this->config['node_author_load_remote'] = $form_state['values']['node_author_load_remote'];
}
/**
* Before sync event.
*/
protected function beforeSync($object) {
if (empty($object->type) && !empty($this->config['node_type'])) {
$object->type = $this->config['node_type'];
}
// Load uid from remote source
if ($this->config['node_author'] == 'load_remote') {
try {
if (!empty($this
->getEntity()->uid)) {
$remote_uid = $this
->getRemoteUserId($this
->getEntity()->uid);
$object->uid = $remote_uid !== NULL ? $remote_uid : $this->config['node_author_load_remote'];
}
} catch (ServicesClientConnectionResponseException $e) {
$e
->log();
$object->uid = $this->config['node_author_load_remote'];
}
}
elseif ($this->config['node_author'] == 'value' && !empty($this->config['node_author_value'])) {
$object->uid = $this->config['node_author_value'];
}
}
/**
* Retrieve remote user ID.
*
* @return mixed|NULL
* If no remote entity exists returns NULL
*/
public function getRemoteUserId($uid) {
$account = user_load($uid);
$result = $this
->getRemoteIdByUUID($account->uuid, 'user', 'user', 'uid');
// Log remote id.
if (!empty($result)) {
$this
->log(ServicesClientLogLevel::DEVEL, "FOUND AUTHOR ID; local uuid : @local_uuid, remote id : @remote_id", array(
'@local_uuid' => $account->uuid,
'@remote_id' => $result,
));
}
else {
$this
->log(ServicesClientLogLevel::DEVEL, "NOT AUTHOR FOUND ID; local uuid : @local_uuid", array(
'@local_uuid' => $account->uuid,
'@remote_id' => $result,
));
}
return $result;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntitySaveHandler:: |
protected | function |
Execute sync action. Overrides EventHandler:: |
|
EntitySaveHandler:: |
public | function |
Execute event and send event to remove endpoint. Overrides EventHandler:: |
|
EntitySaveHandler:: |
protected | function | Retrieve object that should be send to remote site. | |
EventHandler:: |
protected | property | Holds connection to remote server. | |
EventHandler:: |
protected | property | Processed drupal entity in event. | |
EventHandler:: |
protected | property | Initialized plugin classes. | |
EventHandler:: |
protected | property | Stores tags assigned to event. | |
EventHandler:: |
public | function | Add configuration plugin. | |
EventHandler:: |
public | function | Add event tag. | |
EventHandler:: |
protected | function | Allow plugin to react on before sync event. | |
EventHandler:: |
public | function | Break any edit lock for current event. | |
EventHandler:: |
public | function | Clear current object cache. | |
EventHandler:: |
protected | function | Retrieve printed version of any variable. Should be used for logging. | |
EventHandler:: |
public | function | Enqueue item if should be queue. | |
EventHandler:: |
protected | function | Put current entity to queue. | |
EventHandler:: |
protected | function | Generates a UUID v4 using PHP code. | |
EventHandler:: |
public | function | Retrieve UI base url for event. | |
EventHandler:: |
protected | function | Retrieves event connection to remote site. | |
EventHandler:: |
protected | function | Retrieve remote connection id. | |
EventHandler:: |
protected | function | Retrieve controll data for current entity. | |
EventHandler:: |
public | function | Retrieve edit lock if exists (other user is editing same event). | |
EventHandler:: |
public | function | Retrieve current event entity. | |
EventHandler:: |
public | function | Retrieve entity ID. | |
EventHandler:: |
public | function | Retrieve event definition. | |
EventHandler:: |
public | function | Retrieve object cached version of event. | |
EventHandler:: |
public | function | Retrieve current object from cache. If not currently in object cache adds object to object cache. | |
EventHandler:: |
public | function | Retrieve existing plugin. | |
EventHandler:: |
protected | function | Retrieve plugin instance by name and configuration. | |
EventHandler:: |
public | function | Retrieve remote entity ID. | 1 |
EventHandler:: |
protected | function | Load remote ID by UUID based on remote UUID configuration. | |
EventHandler:: |
public | function | Get path prefixed with event specific URL. | |
EventHandler:: |
public | function | Check if event has specific tag. | |
EventHandler:: |
public | function | Determine weather event should be fired automatically on drupal object action like node_save or node_delete. | |
EventHandler:: |
public | function | Determine weather object has been changed by editing configuration and not which isn't stored in permanent storage. | |
EventHandler:: |
public | function | Determine wheather entity is matching event conditions. | |
EventHandler:: |
protected | function | Log messages to Drupal watchdog. | |
EventHandler:: |
protected | function | Log error result from services client operation. | |
EventHandler:: |
public | function | Retrieve instance of object initialized with object cache. | |
EventHandler:: |
public | function | Remove existing plugin from configuration. This does is not saved to DB until save() method is called. | |
EventHandler:: |
public | function | Remove tag from event. | |
EventHandler:: |
public | function | Save current event configuration to database. | |
EventHandler:: |
public | function | Set new connection to remote site. | |
EventHandler:: |
public | function | Set entity for current event. | |
EventHandler:: |
public | function | Store current object state to object cache. | |
EventHandler:: |
public | function | Update plugin configuration. This does is not saved to DB until save() method is called. | |
EventHandler:: |
public | function | Return TRUE if this entity shouldn't be send automatically to all connections. | |
EventHandler:: |
public | function |
Constructor. Overrides ServicesClientPlugin:: |
|
NodeSaveHandler:: |
protected | function |
Before sync event. Overrides EventHandler:: |
|
NodeSaveHandler:: |
public | function |
Configuration form. Overrides EntitySaveHandler:: |
|
NodeSaveHandler:: |
public | function |
Save configuration. Overrides EventHandler:: |
|
NodeSaveHandler:: |
public | function |
Load default plugin configuration. Overrides EntitySaveHandler:: |
|
NodeSaveHandler:: |
public | function | Retrieve remote user ID. | |
ServicesClientPlugin:: |
protected | property | Plugin specific configuration | |
ServicesClientPlugin:: |
protected | property | Event definition | |
ServicesClientPlugin:: |
public | function |
Validate configuration form. Overrides ServicesClientConfigurableInterface:: |
1 |
ServicesClientPlugin:: |
public | function |
Retrieve current plugin configuration. Overrides ServicesClientConfigurableInterface:: |
|
ServicesClientPlugin:: |
public | function |
Set configuration of plugin. Overrides ServicesClientConfigurableInterface:: |