CVS edit link for quiptime

I would like several of my developed modules public.

At the moment are 2 modules:

Explorer8 modus
More node buttons

These modules are developed for Drupal 7.

Comments

quiptime’s picture

Title: quiptime [quiptime] » Module "More node buttons"
Component: Miscellaneous » Code
Status: Postponed (maintainer needs more info) » Needs review
StatusFileSize
new8.82 KB

This module add an Cancel and an Save and continue button to node edit forms.

Requirements
--------------------------------------------------------------------------------------
This module is written for Drupal 7.0+.

Installation
--------------------------------------------------------------------------------------
Copy more_node_buttons.module to your module directory and then enable on the
admin modules page.

Administration
--------------------------------------------------------------------------------------
1. Go to administer content types admin/structure/types and edit a content type.
In section "Submission form settings" please choose in "Manage buttons" the
option to use the Cancel and the Save and continue button.

quiptime’s picture

Title: quiptime [quiptime] » Module "Explorer8 modus"
Component: Miscellaneous » Code
StatusFileSize
new3 KB

The module "Explorer8 modus" allows to define how the Explorer 8 web site shows.

Requirements
------------------------------------------------------------------------------
This module is written for Drupal 7.0+.

Installation
------------------------------------------------------------------------------
Create a directory modules/explorer8_modus and copy all the module's files into
it. Enable the module via the administer modules page.

Administration
------------------------------------------------------------------------------
1. In admin/user/permissions define who can administrate the module.
2. Administer the module in admin/settings/explorer8_modus.

AjK’s picture

Title: Module "More node buttons" » quiptime [quiptime]
Component: Code » Miscellaneous

Please only change the "status" setting of the issue and not the title or component. Thanks.

avpaderno’s picture

Title: Module "Explorer8 modus" » quiptime [quiptime]
Component: Code » Miscellaneous
Status: Needs review » Needs work
  1. function more_node_buttons_install() {
      $types = node_type_get_types();
      foreach ($types as $type) {
        variable_set('more_node_buttons_cancel_' . $type->type, 0);
        variable_set('more_node_buttons_sac_' . $type->type, 0);
      }
    }
    

    There is no need to set Drupal variables to their default value; the second parameter passed to variable_get() is the value returned by the function if the variable is not set.

  2. /**
     * Implement hook_uninstall().
     */
    function more_node_buttons_uninstall() {
      $types = node_type_get_types();
      foreach ($types as $type) {
        variable_del('more_node_buttons_cancel_' . $type->type);
        variable_del('more_node_buttons_sac_' . $type->type);
      }
    }
    

    The function can simply be rewritten as

    /**
     * Implement hook_uninstall().
     */
    function more_node_buttons_uninstall() {
      db_query("DELETE FROM {variable} WHERE name LIKE 'more_node_buttons_cancel\_%');
    }
    

    This saves 2n - 1 queries, where n is the number of content type defined.

  3.       if ($sac > 0) {
            if ($sac == 1) $weight_sac = $form['buttons']['submit']['#weight'] + 0.075;
            if ($sac == 2) $weight_sac = $form['buttons']['submit']['#weight'] + 1.025;
    
          if ($sac == 1) {
            $weight_sac = $form['buttons']['submit']['#weight'] + 0.075;
          }
          elseif ($sac == 2) {
            $weight_sac = $form['buttons']['submit']['#weight'] + 1.025;
         }
    

    See the coding standards on how the code should be written.

  4.         // Deactivate the node validation function.
            unset($form['#validate']);
    

    Validation functions are never removed; you can add more validation functions, but you don't remove the ones set from other modules, which could stop to work.

  5. function more_node_buttons_form_validate($form, &$form_state) {
      if ($form_state['clicked_button']['#id'] == 'edit-cancel') {
        drupal_get_messages('error');
        if (arg(0) === 'node' && arg(1) === 'add') {
          // Limitation: Exist only one content type the redirect does not work.
          drupal_goto('node/add');
    

    Validation functions don't redirect to a different page; their task is to simple validate the input, and report an error if something is wrong.

quiptime’s picture

@KiamLaLuno,

thanks for your short time feedback.

1., 2. and 3. is ok. I will correct the code for these parts.

But,
points 4. and 5.: Here there is a problem that requires a reasonable solution.

Drupal's FAPI knows no solution to disable a validation (temporarily). I do not know any solution for that. One must see the code in context:

        // Deactivate temporarily the node validation function.
        unset($form['#validate']);

        // Initiate own validation function.
        $form['#validate'][] = 'more_node_buttons_form_validate';
function more_node_buttons_form_validate($form, &$form_state) {
  // If clicked Cancel button is no validation required.
  if ($form_state['clicked_button']['#id'] == 'edit-cancel') {
    drupal_get_messages('error');
    if (arg(0) === 'node' && arg(1) === 'add') {
      // Limitation: Exist only one content type the redirect does not work.
      drupal_goto('node/add');
    }
    elseif (arg(0) === 'node' && is_numeric(arg(1)) && arg(2) === 'edit') {
      drupal_goto('node/' . arg(1));
    }
    else {
      drupal_goto('<front>');
    }
  }
  // Important:
  // Reactivate the node validation function.
  if ($form_state['clicked_button']['#id'] != 'edit-cancel') {
    module_invoke_all('node_validate', $form_state['args'][0], $form);
  }
}

One can see that I just temporarily disable validation!

And, it is not validation required, you can realize a redirect at this point. Remember, this is the Cancel button action. There is no other form logic required.
Why should we in such a situation does not realize a redirect in the validation function?

I think my code is not a hack but a solution in coherence with the limitation of FAPI.

avpaderno’s picture

Drupal's FAPI knows no solution to disable a validation (temporarily).

This is what Drupal 5.x to 6.x FormAPI changes reports:

Form buttons can define custom #submit and #validate handlers
All forms can have #validate and #submit properties containing lists of validation and submission handlers to be executed when a user submits data. Previously, if a form featured multiple submission buttons to initiate different actions (updating a record versus deleting, for example), it was necessary to check the incoming $form_values['op'] for the name of the clicked button, then execute different code based on its value.

Now, it is possible to define #validate and #submit properties on each individual form button if desired.

When a specific button is used to submit a form, its validation and submission handlers will be used rather than the default form-level ones. If none are specified at the button level, the form-level handlers will be used instead.

To the question "is it possible to disable the form validate?" I would reply that is possible.
If you are adding a new form button, and you don't want the form is validated when the user clicks on it, you define an empty function that you then use as validate function for that button. You should define a submission function for that button too, I think.

quiptime’s picture

Component: Miscellaneous » Code
StatusFileSize
new8.8 KB

Now I have realized all the tasks. The "More node buttons" module code is rewritten.

@KiamLaLuno, thank you for your inspiration. :-)

Edit:
Don't use attached file from this post. Please use attachement from post #9.

superbaloo’s picture

Status: Needs work » Needs review
quiptime’s picture

StatusFileSize
new8.8 KB

Sorry, my attached file in post #7 has wrong code.

Please use this attached file.

quiptime’s picture

Component: Code » Miscellaneous
StatusFileSize
new9.04 KB

The reorganized validation handling produces a problem.

After the button "Save and continue" was clicked produce any further clicks with any button a form error. This error resulted from the functions node_validate() -> node_last_changed().

if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) {
    form_set_error('changed', t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.'));
  }

I have this problem solved.

avpaderno’s picture

Issue tags: +Module review
avpaderno’s picture

Status: Needs review » Needs work

I am changing the status as per comment #10.

EDIT: I misunderstood the last comment made from the OP.

avpaderno’s picture

Status: Needs work » Needs review
avpaderno’s picture

Issue tags: +Drupal 7.x

As there is not a stable version of Drupal 7, I would wait before to approve this module; Drupal 7 code could be changed before to be stable, and the code of this module should be changed as well.

avpaderno’s picture

Status: Needs review » Postponed
avpaderno’s picture

Status: Postponed » Needs work

The file LICENSE.txt needs to be removed; Drupal.org CVS doesn't allow to commit that file.

I am changing the status, so other people can review the module.

avpaderno’s picture

Status: Needs work » Needs review

I am adding a review tag.

quiptime’s picture

What is mi_ne_recenzias?

The case revolves in a circle.

I would like contribute to another module. But this is not possible. The situation here is in stop status.

Now I must be here every day to see that nothing happens. On the day when drupal 7 is completed, it may be something that will happen eventually. And then, it may still need a long time until someone makes a recension.

Should I register myself as a different user to contribute an other module? I think this is not the right way.

avpaderno’s picture

Should I register myself as a different user to contribute an other module?

No, you should not. Just upload here the new module.

avpaderno’s picture

A note about who approves CVS applications: I am not the only one who does it; there are other people who can do it.
If I am not going to approve this application, this doesn't mean the application will never be approved (or rejected). I am simply not following it because a personal attack made from the OP to me.

avpaderno’s picture

Status: Needs review » Needs work
  1.   elseif (arg(0) === 'admin' && arg(1) === 'structure' && arg(2) === 'types' && arg(3) === 'add') {
        // Use an content type "dummy" to handle button management on "Add content type" page.
        $node_type = 'dummy';
    
        // TODO: Better name as dummy, dummy not unique enough.
      }
      else {
        return;
      }
    
      switch ($form_id) {
        case 'node_type_form':
          if (empty($form['#node_type']->type)) {
            $type = 'dummy';
          }
    

    It would be better to use a different value, when the content type can be determined; dummy is a value that can be used as identifier for a content type, and the module would not be able to understand the different between the settings for an existing content type, and the default values used when it is not possible to retrieve the content type being edited.
    Also, the fact it is not possible to determinate the content type in a content type form is a error condition that cannot be handled; the module should simply exit, in such case.

  2.           '#value' => t('Save and continue'),
              '#access' => TRUE,
    

    The value used for #access is the default one, and it should not be explicitly set.

  3. In more_node_buttons_form_alter() there are two different variables that are used to contain the content type being edited. Was not enough to use a single variable?
  4. /**
     * Implement hook_form_validate().
     *
     * Handle the Cancel button validation.
     */
    function more_node_buttons_cancel_validate($form, &$form_state) {
      // No validation required.
      more_node_buttons_cancel_submit($form, $form_state);
    }
    

    A validation function doesn't call the submission function, as that is already done from Drupal core code. First, it's conceptually not correct (a validation function is supposed to just verify if the entered data is acceptable; secondary, with this code the submission function would be called twice).

  5. What I reported for the file LICENSE.txt is still valid.
  6. /**
     * Implement hook_form_submit().
     */
    function more_node_buttons_changed_submit($form, &$form_state) {
      if ($form_state['clicked_button']['#id'] == 'edit-preview') {
        $form_state['redirect'] = FALSE;
      }
      elseif ($form_state['clicked_button']['#id'] == 'edit-delete') {
        drupal_goto('node/' . $form_state['values']['nid'] . '/delete', 'destination=node/' . $form_state['values']['nid'] . '/edit');
      }
      elseif ($form_state['clicked_button']['#id'] == 'edit-submit') {
        drupal_goto('<front>');
      }
      else {
        $form_state['redirect'] = TRUE;
      }
    }
    

    If the code needs to act differently basing on the submission button the user clicked on, then it should attach a different submission function for each of the buttons it needs to react to. This is clearly stated in Form buttons can define custom #submit and #validate handlers.

  7.     if (preg_match("/dummy/", $key)) {
          // Insert right content type.
          $new_type = preg_replace("/dummy/", $type, $key);
          $form_state['values'][$new_type] = $value;
          // Delete dummy content type.
          unset($form_state['values'][$key]);
        }
    

    preg_match() will return 1 even if the value of the variable $key contains a string like 'dummy_node', or 'not_a_dummy_node'; I am not sure that is wanted.
    Even in the case there would be the need to replace any occurrence of the string 'dummy', it would be enough to use PHP string functions (strpos(), and str_replace(), i.e.).

avpaderno’s picture

The points of my previous comment are not related with the version of Drupal for which the module is thought for.
There is no need to wait until Drupal 7 will have its first stable official release, because those points are valid now, and they will be valid also later.

avpaderno’s picture

Status: Needs work » Closed (won't fix)

The OP has not replied in more than 2 weeks. I am marking this report as won't fix.

quiptime’s picture

Status: Closed (won't fix) » Needs review
StatusFileSize
new9.16 KB

Here are the next round. The next level of "More node buttons" module.

avpaderno’s picture

Status: Needs review » Closed (won't fix)

The application has been marked as won't fix since 5 months ago. Please open a new application.

quiptime’s picture

Status: Closed (won't fix) » Needs review

What does it mean?

Apply for contributions CVS access
or
New CVS applications review

avpaderno’s picture

Status: Needs review » Closed (won't fix)

The current application has been already rejected, as per comment #26; you need to follow the procedure you followed to apply for a CVS account.

jcmc’s picture

Hello Kiam,

The current application has been already rejected, as per comment #26; you need to follow the procedure you followed to apply for a CVS account.

quiptime can't apply or reapply for a CVS account because he gets the message:
<strong>Failure to read and follow this procedure can result in your application being marked as "won't fix".</strong>

If exists another way to apply or reapply for the account please give this information free. Maybe it is a mistake and you don't know what hapens.

I please you to clarify this mistake or wrong funktionality from cvs account request system.

I thank you in advance.

Regards
Juan Carlos

jcmc’s picture

It is now possible,

thanks
Juan Carlos