Register drupal_user_id extra field - refs BT#9413

1.10.x
Angel Fernando Quiroz Campos 10 years ago
parent 7381ce5c03
commit 57ac01ffcb
  1. 2
      plugin/createdrupaluser/lang/english.php
  2. 2
      plugin/createdrupaluser/lang/spanish.php
  3. 56
      plugin/createdrupaluser/src/CreateDrupalUser.php

@ -10,3 +10,5 @@ $strings['plugin_comment'] = 'This plugin creates users in an associated Drupal
$strings['drupal_domain'] = 'Drupal website URL';
$strings['drupal_domain_help'] = 'The server domain name should be written with a trailing slash and with the protocol, e.g. http://www.example.com/';
$strings['DruaplUserId'] = 'Drupal user ID';

@ -10,3 +10,5 @@ $strings['plugin_comment'] = 'Este plugin permite crear usuarios en un sitio web
$strings['drupal_domain'] = 'URL del sitio web Drupal';
$strings['drupal_domain_help'] = 'La dirección del servidor debe escribirse con el protocolo al comienzo y con la barra al final, por ejemplo http://www.example.com/';
$strings['DrupalUserId'] = 'ID de usuario Drupal';

@ -9,6 +9,8 @@
*/
class CreateDrupalUser extends Plugin implements HookPluginInterface
{
const EXTRAFIELD_VARIABLE_NAME = 'drupal_user_id';
/**
* Class constructor
*/
@ -38,6 +40,7 @@ class CreateDrupalUser extends Plugin implements HookPluginInterface
*/
public function install()
{
$this->createExtraField();
$this->installHook();
}
@ -48,6 +51,7 @@ class CreateDrupalUser extends Plugin implements HookPluginInterface
public function uninstall()
{
$this->uninstallHook();
$this->deleteExtraField();
}
/**
@ -74,4 +78,56 @@ class CreateDrupalUser extends Plugin implements HookPluginInterface
}
}
/**
* Get the drupal_user_id extra field information
* @return array The info
*/
private function getExtraFieldInfo()
{
$extraField = new ExtraField('user');
$extraFieldHandler = $extraField->get_handler_field_info_by_field_variable(
self::EXTRAFIELD_VARIABLE_NAME
);
return $extraFieldHandler;
}
/**
* Create the drupal_user_id when it not exists
*/
private function createExtraField()
{
$extraFieldExists = $this->getExtraFieldInfo() !== false;
if (!$extraFieldExists) {
$extraField = new ExtraField('user');
$extraField->save(
[
'field_type' => ExtraField::FIELD_TYPE_INTEGER,
'variable' => self::EXTRAFIELD_VARIABLE_NAME,
'display_text' => get_plugin_lang('DrupalUserId', 'CreateDrupalUser'),
'default_value' => null,
'field_order' => null,
'visible' => false,
'changeable' => false,
'filter' => null
]
);
}
}
/**
* Delete the drupal_user_id and values
*/
private function deleteExtraField()
{
$extraFieldInfo = $this->getExtraFieldInfo();
$extraFieldExists = $extraFieldInfo !== false;
if ($extraFieldExists) {
$extraField = new ExtraField('user');
$extraField->delete($extraFieldInfo['id']);
}
}
}

Loading…
Cancel
Save