Our site's server was recently upgraded to PHP 7.2.14. Drupal version: 7.63. Content Access version: 7.x-1.2-beta2

When modifying access permissions, receive this php warning:

Warning: count(): Parameter must be an array or an object that implements Countable in content_access_page() (line 55 of /[docroot]/sites/all/modules/content_access/content_access.admin.inc).

Comments

memcinto created an issue. See original summary.

memcinto’s picture

Maybe a patch something like this? (Starting at around line 50 of content_access.admin.inc)

  $my_custom_access_grants = content_access_get_per_node_settings($node);
  
  if ($my_custom_access_grants > 0) {
  	$my_custom_access_grants_boolean = TRUE;
  } else {
  	$my_custom_access_grants_boolean = FALSE;
  }

  $form['reset'] = array(
    '#type' => 'submit',
    '#value' => t('Reset to defaults'),
    '#weight' => 10,
    '#submit' => array('content_access_page_reset'),
    // '#access' => count(content_access_get_per_node_settings($node)) > 0,
    '#access' => $my_custom_access_grants_boolean,
  );
salvis’s picture

Please check the -dev version first and provide a patch against that if needed.

tarik.cipix’s picture

Version: 7.x-1.2-beta2 » 7.x-1.x-dev
StatusFileSize
new1015 bytes

Here is a patch

amsteri’s picture

StatusFileSize
new754 bytes
tarik.cipix’s picture

Amsteri,

You're calling the function twice, I fixed it below, also added a question. Not sure about the else contents.

  $res = content_access_get_per_node_settings($node);

  if (is_array($res)) {
    $form['reset']['#access'] = count($res) > 0;
  }
  else {
    // @todo: can we really compare this value with an int?
    $form['reset']['#access'] = $res > 0;
  }
cafuego’s picture

StatusFileSize
new741 bytes

Rather than try to shoe-horn the return value to be countable and then produce a boolean for the #access value, you can check if the returned settings array is empty or not and everything should work as intended without code warnings.

Array empty => #access FALSE => reset button disabled.

salvis’s picture

Status: Active » Needs review

Yes, empty() covers all relevant cases.

joelpittet’s picture

Status: Needs review » Reviewed & tested by the community

That looks like the correct solution for this!

Anonymous’s picture

patch #7 worked for me in php 7.3

  • cafuego authored e3d314e on 7.x-1.x
    Issue #3026681 by tarik.cipix, cafuego, Amsteri, memcinto, salvis,...
gisle’s picture

Status: Reviewed & tested by the community » Fixed

Fixed in 7.1-1.x-dev.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.