Skip to content
Snippets Groups Projects
user-create-form.php 6.36 KiB
Newer Older
<?php
/**
 * Copyright (C) 2019 Leipzig University Library
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * @author  Sebastian Kehr <kehr@ub.uni-leipzig.de>
 * @license http://opensource.org/licenses/gpl-2.0.php GNU GPLv2
 */

use fid_adlr\InputFilter\UserCreateFormInputFilter;
use Laminas\Filter\Boolean;
use Laminas\Filter\StringTrim;
use Laminas\Filter\ToInt;
use Laminas\Form\Element\Checkbox;
use Laminas\Form\Element\Select;
use Laminas\Form\Element\Text;
use Laminas\Validator\NotEmpty;
use Laminas\Validator\Regex;
use Laminas\Validator\StringLength;

return [
    'elements'     => [
        'college'   => [
            'spec' => [
                'attributes' => [
                    'required' => true,
                ],
            ],
        ],
        'job_title' => [
            'spec' => [
                'type'    => Select::class,
                'options' => [
                    'empty_option'  => '',
                    'value_options' => [
                        'job_title_2',
                        'job_title_3',
                        'job_title_4',
                        'job_title_5',
                        'job_title_6',
                        'job_title_7',
                        'job_title_8',
                        'job_title_9',
                    ],
                ],
            ],
        ],
        'addresses' => require 'address-collection.php',
        'data'      => [
            'spec' => [
                'elements' => [
                    'phone'            => [
                        'spec' => [
                            'name'    => 'phone',
                            'type'    => Text::class,
                            'options' => [
                                'label' => 'label_phone',
                            ],
                            'attributes' => [
                                'autocomplete' => 'tel',
                                'id' => 'phone'
                            ],
                        ],
                    ],
                    'newsletter'       => [
                        'spec' => [
                            'name'    => 'newsletter',
                            'type'    => Checkbox::class,
                            'options' => [
                                'label' => 'label_newsletter',
                            ],
                        ],
                    ],
                    'delivery_address' => [
                        'spec' => [
                            'name'    => 'delivery_address',
                            'type'    => Checkbox::class,
                            'options' => [
                                'label' => 'label_delivery_address',
                            ],
                        ],
                    ],
                ],
                'options'  => [
                    'input_filter_spec' => [
                        'phone'            => [
                            'name'       => 'phone',
                            'required'   => false,
                            'filters'    => [
                                StringTrim::class => [
                                    'name' => StringTrim::class,
                                ],
                            ],
                            'validators' => [
                                StringLength::class => [
                                    'name'    => StringLength::class,
                                    'options' => [
                                        'max' => 255
                                    ],
                                ],
                            ],
                        ],
                        'newsletter'       => [
                            'name'       => 'newsletter',
                            'filters'    => [
                                Boolean::class => [
                                    'name' => Boolean::class,
                                ],
                            ],
                            'validators' => [
                                NotEmpty::class => [
                                    'name'    => NotEmpty::class,
                                    'options' => [
                                        'type' => NotEmpty::NULL,
                                    ],
                                ],
                            ],
                        ],
                        'delivery_address' => [
                            'name'       => 'delivery_address',
                            'filters'    => [
                                ToInt::class => [
                                    'name' => ToInt::class,
                                ],
                            ],
                            'validators' => [
                                NotEmpty::class        => [
                                    'name'    => NotEmpty::class,
                                    'options' => [
                                        'type' => NotEmpty::NULL,
                                    ],
                                ],
                            ],
                        ],
                    ],
                ],
            ],
        ],
    ],
    'input_filter' => [
        'type'    => UserCreateFormInputFilter::class,
        'college' => [
            'required' => true,
        ],
        'password'             => [
            'validators' => [
                Regex::class        => [
                    'name'    => Regex::class,
                    'options' => [
                        'pattern'  => '/(?:.*[0-9].*[A-Z].*|.*[A-Z].*[0-9].*)/',
                        'messages' => [
                            Regex::NOT_MATCH => 'error_password_pattern',
                        ],
                    ],
                ],
            ],
        ],