Skip to content
Snippets Groups Projects

i6859 revert accidental commit to shareholder number

Merged simon requested to merge revert-i6859-change-to-shareholder-number into master
Compare and
1 file
+ 9
59
Preferences
File browser
Compare changes
@@ -5,7 +5,6 @@ namespace Drupal\shareholder_register_webform\Element;
use Drupal\Component\Utility\Html;
use Drupal\webform\Element\WebformCompositeBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\user\Entity\User;
/**
* Provides a 'shareholder_number'.
@@ -34,66 +33,17 @@ class ShareholderNumber extends WebformCompositeBase {
// Generate an unique ID that can be used by #states.
$html_id = Html::getUniqueId('shareholder_number');
$elements = [];
$user = User::load(\Drupal::currentUser()->id());
if ($user->hasField('shareholders') &&
count($user->get('shareholders')->getValue())) {
$existing_options = [];
foreach ($user->get('shareholders')->referencedEntities() as $shareholder) {
$existing_options[$shareholder->id()] = $shareholder->label();
}
$existing_options['other'] = t('Other existing shareholder');
$elements += [
'shareholder' => [
'#type' => 'radios',
'#options' => $existing_options,
'#attributes' => [
'name' => 'shareholder',
],
],
];
}
else {
$elements += [
'shareholder' => [
'#type' => 'hidden',
'#value' => 'other',
'#attributes' => [
'name' => 'shareholder',
],
],
];
}
$elements += [
'existing_data' => [
'#type' => 'fieldset',
'#states' => [
'visible' => [
':input[name="shareholder"]' => ['value' => 'other'],
],
],
'number' => [
'#type' => 'textfield',
'#title' => t('Shareholder Number'),
'#attributes' => ['data-webform-shareholder-number-id' => $html_id . '--number'],
],
'mail' => [
'#type' => 'textfield',
'#title' => t('Registered Mail'),
'#attributes' => ['data-webform-shareholder-number-id' => $html_id . '--mail'],
],
$elements = [
'number' => [
'#type' => 'textfield',
'#title' => t('Shareholder Number'),
'#attributes' => ['data-webform-shareholder-number-id' => $html_id . '--number'],
],
'new' => [
'#type' => 'radio',
'#name' => 'shareholder',
'#title' => t('New Shareholder'),
'mail' => [
'#type' => 'textfield',
'#title' => t('Registered Mail'),
'#attributes' => ['data-webform-shareholder-number-id' => $html_id . '--mail'],
],
'shareholder_id' => [
'#type' => 'value',
],