gcode-mirror / google-highly-open-participation-drupal

Automatically exported from code.google.com/p/google-highly-open-participation-drupal
0 stars 0 forks source link

custom validating hook for CCK #169

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
CCK is one of the most widely used contributed modules for Drupal. It
allows site administrators to customize their content types by adding any
number of additional fields (text, number, date, image...), without writing
a single line of code.

One missing feature is user-configurable validation steps, that currently
do require manual coding and trickery. This has lead to the proliferation
of CCK field modules that are simply a text field with some formatting
logic applied to them, such as for a UK telephone number, a US social
security number, an email address... In many cases, however, a full CCK
field module is unnecessary and all that is needed is extra validation
capability, which would eliminate a lot of needless code and provide
additional flexibility for site administrators.

The goal of this task is to add a support for user-configurable validators
for any CCK field type. It should be targetted as a patch to the HEAD (for
Drupal 6) version of CCK's content.module.

* When configuring a field, as part of the field configuration (not widget
configuration), allow the user to select a validation rule from a list.
Each validation rule must have a name/label and optionally a minimal
configuration. Use of Drupal 6's new AHAH-add-fields functionality here is
encouraged.
In order to simplify the form workflow management, the scope of this task
is limited to 1 validation rule per field for now.

* The list of available validation rules will be provided by a new hook,
exposed by the content.module. Any module may define an arbitrary number of
validators that it offers for any field type. Each validator should work by
accepting the value of the field and the configuration of the validator (if
applicable) to a callback function and returning TRUE (indicating that it
passes validation) or FALSE (indicating that it failed).

* When validating a submitted field, the content.module should call the
configured validator with the submitted content. If the validator fails,
the field should fail validation with an appropriate error message.

* At least two validators for text fields will be implemented in this task
: A user-defined regular expression (PCRE) and user-supplied PHP code that
will return TRUE or FALSE.

* Although it is not required for this task, a later task will include
pushing a regular expression check out to the user-side where it can be
validated with Javascript/jQuery as well. Do not implement that
functionality here, but keep it in mind so that it is reasonable to add it
later.

The API for validators can be largely derived from the existing API for
widgets and formatters :
- hook_validator_info() lets modules declare the validators they implement,
along with the field type(s) they can operate on.
- hook_validator_settings() lets them declare the $form to use for settings
(just like 'form' / 'save' ops for hook_widget_settings)
- hook_validator() performs the actual validation of the field values.

The task is completed when the patch has been posted to the CCK issue queue
and reviewed and marked "Ready to be committed" by one of the CCK maintainers.

Mentors :
yched, KarenS

Ressources :
- CCK HEAD for Drupal 6 : http://drupal.org/node/96064
- the sample fields provided in the 'examples' folder in CCK HEAD.
- 'CCK for developpers' handbook : http://drupal.org/node/101742

Original issue reported on code.google.com by y.chedem...@gmail.com on 21 Jan 2008 at 9:03

GoogleCodeExporter commented 9 years ago

Original comment by webchick...@gmail.com on 21 Jan 2008 at 9:08

GoogleCodeExporter commented 9 years ago

Original comment by acli...@gmail.com on 23 Jan 2008 at 2:51