Skip to content
Snippets Groups Projects
Commit 34f8c1bf authored by Nejc Koporec's avatar Nejc Koporec
Browse files

Cleanup, fix phpcs issues

parent 2746907c
Branches feat/custom-user-add-form
No related tags found
No related merge requests found
......@@ -38,8 +38,10 @@ class SpaceUserAddForm extends SpaceUserBaseForm {
'#type' => 'fieldset',
'#states' => [
'visible' => [
':input[name="type"]' => ['value' => 'existing'],
]
':input[name="type"]' => [
'value' => 'existing',
],
],
],
];
......@@ -48,7 +50,9 @@ class SpaceUserAddForm extends SpaceUserBaseForm {
'#title' => $this->t('Email address'),
'#states' => [
'required' => [
':input[name="type"]' => ['value' => 'existing'],
':input[name="type"]' => [
'value' => 'existing',
],
],
],
];
......@@ -57,7 +61,9 @@ class SpaceUserAddForm extends SpaceUserBaseForm {
'#type' => "fieldset",
'#states' => [
'visible' => [
':input[name="type"]' => ['value' => 'new'],
':input[name="type"]' => [
'value' => 'new',
],
],
],
];
......@@ -66,25 +72,33 @@ class SpaceUserAddForm extends SpaceUserBaseForm {
$form['user_wrapper']['user']['mail']['#states'] = [
'required' => [
':input[name="type"]' => ['value' => 'new'],
':input[name="type"]' => [
'value' => 'new',
],
],
];
$form['user_wrapper']['user']['name']['#states'] = [
'required' => [
':input[name="type"]' => ['value' => 'new'],
':input[name="type"]' => [
'value' => 'new',
],
],
];
$form['user_wrapper']['user']['password']['#states'] = [
'required' => [
':input[name="type"]' => ['value' => 'new'],
':input[name="type"]' => [
'value' => 'new',
],
],
];
$form['user_wrapper']['user']['confirm_password']['#states'] = [
'required' => [
':input[name="type"]' => ['value' => 'new'],
':input[name="type"]' => [
'value' => 'new',
],
],
];
......@@ -101,7 +115,7 @@ class SpaceUserAddForm extends SpaceUserBaseForm {
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
$values = $form_state->getValues();
$type = isset($values['type']) ? $values['type'] : NULL;
$type = isset($values['type']) ?: $values['type'];
if (!$type) {
$form_state->setErrorByName(
......@@ -320,7 +334,6 @@ class SpaceUserAddForm extends SpaceUserBaseForm {
$saved_users[$item['target_id']] = $item['target_id'];
}
$saved_users[$user->id()] = $user->id();
$space_entity->editors = $saved_users;
......@@ -333,4 +346,5 @@ class SpaceUserAddForm extends SpaceUserBaseForm {
),
);
}
}
......@@ -118,6 +118,7 @@ abstract class SpaceUserBaseForm extends FormBase {
* Gets the entity type manager.
*
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
* Entity type manager.
*/
protected function entityTypeManager() {
return $this->entityTypeManager;
......@@ -127,6 +128,7 @@ abstract class SpaceUserBaseForm extends FormBase {
* Gets the module handler.
*
* @return \Drupal\Core\Extension\ModuleHandlerInterface
* Module handeler.
*/
protected function moduleHandler() {
return $this->moduleHandler;
......@@ -136,6 +138,7 @@ abstract class SpaceUserBaseForm extends FormBase {
* Gets the form builder.
*
* @return \Drupal\Core\Form\FormBuilderInterface
* Form builder.
*/
protected function formBuilder() {
return $this->formBuilder;
......@@ -145,6 +148,7 @@ abstract class SpaceUserBaseForm extends FormBase {
* Gets the space entity.
*
* @return \Drupal\nodehive_core\SpaceInterface
* Space entity.
*/
protected function getSpaceEntity() {
return $this->space;
......@@ -256,7 +260,7 @@ abstract class SpaceUserBaseForm extends FormBase {
$form['picture_wrapper'] = [
'#type' => 'details',
'#title' => t('Picture'),
'#title' => $this->t('Picture'),
'#open' => TRUE,
];
......@@ -264,11 +268,11 @@ abstract class SpaceUserBaseForm extends FormBase {
'#type' => 'managed_file',
'#upload_location' => 'public://',
'#multiple' => FALSE,
'#description' => t('Allowed extensions: gif png jpg jpeg'),
'#description' => $this->t('Allowed extensions: gif png jpg jpeg'),
'#upload_validators' => [
'file_validate_is_image' => [],
'file_validate_extensions' => ['gif png jpg jpeg'],
'file_validate_size' => [25600000]
'file_validate_size' => [25600000],
],
'#title' => $this->t('Upload an image file for this user'),
'#default_value' => $user->isNew() ? NULL : $user->user_picture->target_id,
......@@ -289,8 +293,8 @@ abstract class SpaceUserBaseForm extends FormBase {
];
$user_form = $this->entityTypeManager()
->getFormObject('user', 'default')
->setEntity($user);
->getFormObject('user', 'default')
->setEntity($user);
$user_form = $this->formBuilder()->getForm($user_form);
$form['advanced']['language'] = [
......
......@@ -111,7 +111,6 @@ class SpaceUserEditForm extends SpaceUserBaseForm {
$saved_users[$item['target_id']] = $item['target_id'];
}
$saved_users[$user->id()] = $user->id();
$space_entity->editors = $saved_users;
......@@ -143,4 +142,5 @@ class SpaceUserEditForm extends SpaceUserBaseForm {
->getStorage('user')
->load($user_id);
}
}
......@@ -127,7 +127,7 @@ class SpaceUserListBuilderForm extends FormBase {
'#title' => $this->t("Number of users: @number", ['@number' => count($users)]),
'#attributes' => [
'class' => [
'number-of-users'
'number-of-users',
],
],
];
......@@ -152,7 +152,7 @@ class SpaceUserListBuilderForm extends FormBase {
if (!$user->user_picture->isEmpty()) {
$picture = $user->user_picture->entity->getFileUri();
}
else{
else {
$picture = '';
}
......@@ -161,7 +161,7 @@ class SpaceUserListBuilderForm extends FormBase {
'#theme' => 'image_style',
'#style_name' => 'thumbnail',
'#uri' => $picture,
]
],
];
$row[] = $user->getAccountName();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment