メインコンテンツに移動

メインナビゲーション

  • ホーム
  • サイトマップ
  • ビデオ
  • ご連絡

パンくず

  • ホーム
  • Drupalのモジュール(Entity Reference)で作成した記事からほかの記事への参照リンク作成

Drupalのモジュール(Entity Reference)で作成した記事からほかの記事への参照リンク作成

drupal
video
entity api
module usage

やりたいこと:作成した記事からほかの記事への参照リンクをつけたいです

  • シリーズの記事作成するとに、記事からほかの記事への参照リンクをつけるので必要となります
  • 書いた文書ないで参照リンクをつけることができますが、参考リンクを記事から別の場所で配置したりすることがコンテンツタイプではできないです

解決:モジュール(Entity Reference)でほかの記事を参照リンク作成

  • 他の記事を参照するモジュールはNode Referecneもありますが、Drupal7がEntityの概念を導入したので、より幅広く参照ができるようになるのはEntity Referenceです(Node Referecneが非推奨)
  • Enity Reference:7.x-1.2
  • Enity Referenceのインストール/設定/参照フィールド作成方法と手順などはビデオをご参考ください
Embedded thumbnail for Drupalのモジュール(Entity Reference)で作成した記事からほかの記事への参照リンク作成
drupal
video
entity api
module usage
views

やりたいこと:他の記事参照選択時に大量な記事を検索/選択機能がほしいです

  • 記事作成時に、シリーズの記事が関連記事への参照リンクが必要となります。(Drupalのモジュール(Entity Reference)で作成した記事からほかの記事への参照リンク作成)
  • 作成された記事が多ければ、必要な記事の検索/選択機能必要となります
  • 既存のEnity Referenceがこの検索機能が提供されていないです

解決:モジュール(Entity Reference View Widget)で多量な記事を検索/選択を行います

  • モジュール(Entity Reference View Widget):7.x-2.0-RC7 のインストール/有効化
  • モジュール(Views):7.x-3.14
  • モジュールのインスト―ル、有効化、設定などをビデオでご参考ください
  • Entity Reference Views Widgetがタグで選択だけではなく、キーワードなどの検索追加も可能です
Embedded thumbnail for Drupalのモジュール(Entity Reference Views Widget)で大量の記事から検索検索/選択
drupal
video
entity api
module usage

やりたいこと:Entity Referenceで参照されている記事が自動的に参照してきた記事の参照関係をつけます

  • モジュール:Entity Referenceで一コンテンツ(例:記事)が複数のほかの記事を参照することができます(Drupalのモジュール(Entity Reference)で作成した記事からほかの記事への参照リンク作成)
  • モジュール:Entity Referenceが二つの記事を相互参照を指定する場合、通常2回で各記事内で指定する必要があります
    • 記事1の編集で ⇒ 記事2 を参照指定
    • 記事2の編集で ⇒ 記事1 を参照指定(逆参照指定)
  • このような指定方法が面倒で、参照しようとする記事が多ければ、逆参照設定は仕事量が増大します

解決:モジュール:Corresponding Entity Referecnecesで逆参照が自動的につけます

  • Corresponding Entity References:7.x-3.0-alpha7
  • 通常の方法でインストール/有効化を行います
  • Corresponding Entity Referencesの管理画面(ホーム » 管理 » 環境設定 » コンテンツ作成 » Corresponding Entity References)で自動参照対象設定を行います
  • 具体的な手順と設定方法をビデオをご参考ください
Embedded thumbnail for DrupalのCorresponding Entity Referencesモジュールで参照しに来たコンテンツを自動に関連付け
drupal
video
entity api
module usage
views

やりたいこと:他の記事参照選択時に大量な記事を検索/選択機能がほしいです

  • 記事作成時に、シリーズの記事が関連記事への参照リンクが必要となります。(Drupalのモジュール(Entity Reference)で作成した記事からほかの記事への参照リンク作成)
  • 作成された記事が多ければ、必要な記事の検索/選択機能必要となります
  • 既存のEnity Referenceがこの検索機能が提供されていないです

解決:モジュール(Entity Reference View Widget)で多量な記事を検索/選択を行います

  • モジュール(Entity Reference View Widget):7.x-2.0-RC7 のインストール/有効化
  • モジュール(Views):7.x-3.14
  • モジュールのインスト―ル、有効化、設定などをビデオでご参考ください
  • Entity Reference Views Widgetがタグで選択だけではなく、キーワードなどの検索追加も可能です
Embedded thumbnail for Drupalのモジュール(Entity Reference Views Widget)で大量の記事から検索検索/選択
drupal
video
entity api
module usage

やりたいこと:作成した記事からほかの記事への参照リンクをつけたいです

  • シリーズの記事作成するとに、記事からほかの記事への参照リンクをつけるので必要となります
  • 書いた文書ないで参照リンクをつけることができますが、参考リンクを記事から別の場所で配置したりすることがコンテンツタイプではできないです

解決:モジュール(Entity Reference)でほかの記事を参照リンク作成

  • 他の記事を参照するモジュールはNode Referecneもありますが、Drupal7がEntityの概念を導入したので、より幅広く参照ができるようになるのはEntity Referenceです(Node Referecneが非推奨)
  • Enity Reference:7.x-1.2
  • Enity Referenceのインストール/設定/参照フィールド作成方法と手順などはビデオをご参考ください
Embedded thumbnail for Drupalのモジュール(Entity Reference)で作成した記事からほかの記事への参照リンク作成
drupal
development
entity type

やりたいこと:複数のEntityreference値をコンテンツにインポート

  • 以下の実例:単語と例文
    EntityReferenceモジュールで一つ単語に複数の例文を参照
  • 構成は:単語コンテンツタイプ、例文コンテンツタイプをそれぞれ作成します
  • 単語コンテンツタイプにEnityreferenceで例文コンテンツタイプを参照します
  • Enityreferenceに関する詳細は記事:「 Drupalのモジュール(Entity Reference)で作成した記事からほかの記事への参照リンク作成 」を参考にしてください
  • 二つのテーブルにあるデータはそれぞれインポートされたものので、関連付けはありません
  • 単語に複数の例文参照できるようにする場合以下のステップが必要
    • 単語を用いて例文テーブルで単語が含まる例文をすべて取得
    • 取得した例文を単語IDをコンテンツにEntityreferenceフィールドに保存

実現手法:FeedsAPIを利用してカスタムモジュールを作成して、単語に複数の例文参照データをインポートします

  • 単一のEntityreference値をコンテンツにインポートするサブモジュールがあります( FeedsモジュールでEnityにデータインポート )
  • 複数のEnityreference値をコンテンツにインポートするサブモジュールはありません
  • ここで、FeedsAPIを利用して、カスタムモジュールを作成することにします
  • 必要なモジュール:Feeds SQL7.x-1.0
    • 単語テーブルをスキャンして、単語のIDと単語を取得します
  • カスタムモジュール(hook_feeds_processor_targets_alter)で各単語の例文を探して、単語のEntityreferenceフィールドにセットします
    • hook_feeds_processor_targets_alterを実装して、ノードプロセッサーのマッピングターゲットに専用フィールドを追加します
      /**
       * Implements hook_feeds_processor_targets_alter().
       */
      function my_module_feeds_feeds_processor_targets_alter(array &$targets, $entity_type, $bundle)
      {
        if( $entity_type=="node"&&$bundle=="chinese_word"){
          $field_info = field_info_instances("node", "chinese_word") ;
          if( array_key_exists('field_ch_word_sentences', $field_info ) &&
              field_info_field( 'field_ch_word_sentences' )['type'] == "entityreference" ){
            $targets["field_ch_word_sentences:drills_hander"] = array(
              'name' => check_plain( $field_info['field_ch_word_sentences']['label'] ).t(' (Import multiple value instance field)'),
              'callback' => 'drills_custom_feeds_set_target_entity_reference',
              'description' => t('This filed for converting Chinese Examples to word reference only.Do not use it for other fields!!'),
            );
          }
        }
      }
      
    • Feedsの管理画面(ホーム » 管理 » サイト構築 » Feedsインポーター)で上記コードで追加されたフィールド(
      例句 (Import multiple value instance field) (field_ch_word_sentences:drills_hander)
      )は以下のようカスタムモジュールがFeedsAPIを利用してマッピングターゲットに専用のフィールドを作成
    • 単語を用いて例文を検索、取得して、単語コンテンツにあるEntityreferenceフィールドにセット(専用フィールドのコールバック関数:drills_custom_feeds_set_target_entity_reference)
      function drills_custom_feeds_set_target_entity_reference($source, &$entity, $target, $value, $mapping){
        if (empty($value)) {
          return;
        }
        $target = str_replace(':drills_hander', '', $target);
        $query = db_query("select title, nid, CHAR_LENGTH(title) as char_num from node where title like '%".$value[0]."%' and type='example_sentences'  order by char_num limit 100");
        $sentences = $query->fetchAll();
        $field = array();
        foreach( $sentences as $i => $sentence ){
          $field[LANGUAGE_NONE][$i]['target_id'] = $sentence->nid;
        }
        $entity->{$target} = $field;
      }

       

ホーム

古松

検索

Article Category

  • apache(7)
  • css(19)
  • drupal(295)
  • Electron(4)
  • html(34)
  • javascript(27)
  • laravel(4)
  • linux(5)
  • macOS(2)
  • mysql(13)
  • php(19)
  • python(4)
  • SEO(12)
  • video(72)
  • Visual Studio Code(4)
  • windows(13)
  • wordpress(32)