简体   繁体   English

PHP和Drupal:在Drupal中使用php时,如何隐藏/显示我的链接?

[英]Php and Drupal: how do I hide/display my link when needed using php within Drupal?

Perhaps it is easier if I ask the question this way - Using the coding snippet below, how would I write the code to display the "Change" link only when the value in status is "A"? 如果我这样问问题,也许会更容易-使用下面的代码片段,仅当状态值为“ A”时,我将如何编写代码以显示“ Change”链接?

I think i'm making this harder than it has to be, but the use of both drupal module structure and php are throwing me, since i am just learning module development. 我认为我正在使此过程变得比原来更难,但是使用drupal模块结构和php都使我不知所措,因为我只是在学习模块开发。

The link showing in the array below appears at the end of each of my rows. 下面数组中显示的链接出现在我的每一行的末尾。 I only want it to appear when the status equals "A". 我只希望状态为“ A”时显示它。

Because this link is within this array, i can't figure out how and where to implement it. 因为此链接在此数组内,所以我不知道如何以及在何处实现它。 I just want an [if statement] like this: 我只想要这样的[if语句]:

if (drupal_render($form['status'][$key]['status']) == 'A',)
echo l(t('Change'), 'rooms/avail_room/' . $key . '/' . arg(1), array('attributes' => array('class' => 'room-stat-avail'))),
else{
echo "";
}

so when the html table is displayed, the ' Change ' link will only appear in the last column when the value of status is "A" 所以在显示HTML表时,“ 更改 ”链接只会出现在最后一栏时的状态值是“A”

Can't believe I got the module working, but can't turn this link on/off as i want. 不敢相信我的模块正常工作,但无法根据需要打开/关闭此链接。 See code snippet below: 请参见下面的代码段:

function team_room_available_form($form) {
    $output = "No space available.";

  if ($form['roomid']) {
    foreach (element_children($form['roomid']) as $key) {
      $rows[] = array(
        'data' => array(
          drupal_render($form[''][$key]),
          drupal_render($form['room_title'][$key]),
          drupal_render($form['username'][$key]),
          drupal_render($form['status'][$key]['status']),
          l(t('Change'), 'rooms/avail_room/' . $key . '/' . arg(1), array('attributes' => array('class' => 'room-stat-avail'))),
        ),
        'class' => $form['status'][$key]['#value'],
      );
    }

You shouldn't really call drupal_render() on every element of your array. 您不应该真正在数组的每个元素上调用drupal_render()。

drupal_render is a theming function to be applied on a renderable array. drupal_render是要应用于可渲染数组的主题函数。 Check the drupal docs on drupal.org ... Render Arrays in Drupal 7 在drupal.org上检查drupal文档。Drupal 7中的渲染数组

Practically this means that you should apply your logic within your module before creating your renderable array. 实际上,这意味着您应该在创建可渲染数组之前在模块中应用逻辑。 Practically your renderable array is just a bunch of values that follows Drupal theming structure. 实际上,可渲染数组只是遵循Drupal主题结构的一堆值。

When you create your array, your logic is just typical PHP. 创建数组时,逻辑只是典型的PHP。 With Drupal you should really try the devel module. 使用Drupal,您应该真正尝试使用devel模块。 It will help you to output your results and help you debug your code. 它将帮助您输出结果并帮助您调试代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM