【问题标题】:Drupal 8 how to alter paragraph form?Drupal 8 如何更改段落格式?
【发布时间】:2020-09-24 07:47:47
【问题描述】:

在 drupal 8 中,我在节点中使用段落。它工作正常,但我被困在改变段落形式。我想在其他字段值的基础上隐藏一个字段。

如果有人以前做过,请帮忙

【问题讨论】:

    标签: drupal-8 drupal-modules


    【解决方案1】:

    我发现下面的代码很有帮助并解决了我的问题。我希望它对其他人也有用。

    function hook_inline_entity_form_entity_form_alter(&$entity_form, &$form_state) {
     
    // $entity_form['#bundle']  paragraph machine name
      if($entity_form['#entity_type'] == 'paragraph' && $entity_form['#bundle'] == 'location'){
        $parents = $entity_form['#parents'];
        $identifier = $parents[0].'['.implode('][', array_slice($parents, 1)).']';
        $entity_form['field_dropoff_time']['#states'] = array(
          'visible' => array(
            'select[name="'. $identifier .'[field_camp_location_type]"]' => ['value' => 1]
          ),
        );
        $entity_form['field_pickup_time']['#states'] = array(
          'visible' => array(
            'select[name="'. $identifier .'[field_camp_location_type]"]' => ['value' => 1]
          ),
        );
      }
    
    }

    【讨论】:

      猜你喜欢
      • 2018-10-05
      • 2021-02-23
      • 2018-06-27
      • 2017-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-25
      相关资源
      最近更新 更多