[英]count(): Parameter must be an array or an object that implements Countable in
[英]Drupal: count(): Parameter must be an array or an object that implements Countable
警告:count():參數必須是在invTranslate_translated_menu_link_alter()(來自\\ sites \\ all \\ modules \\ custom \\ invTranslate \\ invTranslate.module的第55行)中實現Countable的數組或對象。
invTranslate.module是一個自定義模塊。
function invTranslate_translated_menu_link_alter(&$item) {
static $nodeMenu;
if ($nodeMenu === NULL) {
if (arg(0) == 'node' && count(arg() == 3 && (arg(1) == 'add' || arg(2) == 'edit'))) {
$nodeMenu = true;
...
第55行是: if (arg(0) == 'node' && count(arg() == 3 && (arg(1) == 'add' || arg(2) == 'edit'))) {
。 請幫忙。
對我來說,似乎有一個簡單的錯字,但這取決於您的代碼應該做什么。 我將代碼分成多行以提高可讀性:
if (
arg(0) == 'node'
&& count(arg() == 3 //the count method takes as param the bool from the row below too
&& (arg(1) == 'add' || arg(2) == 'edit'))
) {
相反,它應如下所示:
if (
arg(0) == 'node'
&& count(arg()) == 3 // add right bracket after arg()
&& (arg(1) == 'add' || arg(2) == 'edit') // remove right bracket from here
) {
arg()返回當前Drupal路徑的組成部分。 例如,當在路徑“ admin / structure / types”上查看頁面時,arg(0)返回“ admin”,arg(1)返回“ structure”,而arg(2)返回“ types”。 https://api.drupal.org/api/drupal/includes%21bootstrap.inc/function/arg/7.x
在durpal中,節點的路徑如下
回顧一下代碼: if (arg(0) == 'node' && count(arg() == 3 && (arg(1) == 'add' || arg(2) == 'edit')))
我認為,該條件僅適用於我提到的路徑的前2條。 因此,將代碼更改為以下代碼應會導致預期的行為: if (arg(0) == 'node' && count(arg()) == 3 && (arg(1) == 'add' || arg(2) == 'edit'))
count()僅應檢查路徑中是否有足夠的組件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.