contaobayern/contao-member-contact-settings

Member contact settings extension for Contao Open Source CMS

1.1.0 2018-01-21 12:33 UTC

This package is auto-updated.

Last update: 2024-12-18 16:50:00 UTC


README

Member contact settings extension for Contao Open Source CMS

Overview

This module enhances the core modules Registration and MemberData by adding fields that control the allowed contact settings for the registered frontend user.

Installation via Composer

Search package contaobayern/contao-member-contact-settings and install as usual. For Contao 4.4.x use the Contao Manager to install the extension.

Manual Installation

  1. Download the files from the GitHub repository. Rename the folder to member-contact-settings and save under system/modules.
  2. Update your database and clear the internal cache.

Please note

This module's JavaScript will not work with table layouts (i.e. if "Tableless layout" is not checked in the module's definition). This applies to Contao 3 only, as Contao 4 only has templates for tableless layouts. So if you want to use this extension with table layouts you must uncheck the "Control field dependencies with JavaScript" option in your registration and personal data frontend modules.

Setup

The setup is the same for both frontend modules (registration and member data):

  1. Create a new frontend module of the type "registration" or "member data".
  2. Define the form as usual.
  3. With the new fields you can add dependencies. For example if you add "contactPhone" the field "phone" will become mandatory when the user checks "contactPhone". A list of all dependencies is given below.
  4. Sort the field as you wish. It makes sense to put the dependent fields right below the field from which they depend.
  5. By default field dependencies are controlled on client side via JavaScript (jQuery must be enabled in page layout). If you do not want to use JavaScript setting of mandatory status you can uncheck the according option.
  6. With the "Toggle visibility of dependent fields" option you can choose if depedent fields shall be hidden when they are not mandatory (can only be used with JavaScript enabled).

New fields and dependencies in tl_member

Adding your own dependencies

Dependencies are defined in the tl_member DCA. In the eval array of each field which has dependencies there is a new entry dependents:

$GLOBALS['TL_DCA']['tl_member']['fields']['contactLetter'] = [
    // ...
    'eval' => [
        // ...
        'dependents' => [
            'mandatory' => ['street', 'postal', 'city', 'country'],
            'visibility' => ['street', 'postal', 'city', 'country'],
        ],
        // ...
    ]
]

The array mandatory contains the names of the fields which shall be set to mandatory when the parent field is checked. The array visibility contains the names of the fields which shall be shown or hidden according to the parent field.

You can add or modify dependencies in the system\config\dcaconfig.php file.

For example if you want to add state to the dependencies of contactLetter. You can do so by adding the following code to system\config\dcaconfig.php:

$GLOBALS['TL_DCA']['tl_member']['fields']['contactLetter']['eval']['dependents']['mandatory'][] = 'state';
$GLOBALS['TL_DCA']['tl_member']['fields']['contactLetter']['eval']['dependents']['visibility'][] = 'state';

You can also create new dependencies for your own fields wherever you need them:

$GLOBALS['TL_DCA']['tl_member']['fields']['myCheckbox']['eval']['dependents'] = [
    'mandatory' => ['fieldA', 'fieldB', 'fieldC'],
    'visibility' => ['fieldA', 'fieldB', 'fieldC'],
];

Attention: a field which is mandatory by default should not be put in any dependents list. Otherwise its mandatory status will be controlled by the parent field which is unwanted because the field should always be mandatory.