Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Drupal モジュール開発入門講座 第1回 モジュールの基礎知識

Drupal モジュール開発入門講座 第1回 モジュールの基礎知識

More Decks by アクイアジャパン Acquia Japan

Other Decks in Programming

Transcript

  1. ΞδΣϯμ 1. Ϟδϡʔϧͱ͸ 2. Ϟδϡʔϧ։ൃͷલఏ஌ࣝ 3. Ϟδϡʔϧͷछྨ 4. Ϟδϡʔϧͷ؅ཧ 5.

    ϞδϡʔϧͷσΟϨΫτϦߏ੒ͱϑΝΠϧ 6. Drupal؀ڥͷ༻ҙ 7. ࿅श໰୊
  2. DrupalͰར༻͍ͯ͠ΔSymfonyίϯϙʔωϯτ – Yaml – HttpFoundation – HttpKernel – Translation –

    EventDispatcher – Console – DependencyInjection – Polyfill Iconv – Polyfill PHP 8.0 – Process – Routing – Mime – Validator – Serializer
  3. Ξϊςʔγϣϯ – Ξϊςʔγϣϯͱ͸ɺϝλσʔλΛද͢ಛ ผͳߏจͰ͢ɻ – PHPͷDocίϝϯτ( /** */ )಺ʹ@͔Β࢝·Δ ΩʔϫʔυͰࢦఆ͠·͢ɻ

    – Ξϊςʔγϣϯ͸Doctrine annotation parser ʹΑͬͯಡΈࠐ·ΕɺDrupal͕ίʔυͷ಺ ༰Λཧղ͢ΔͨΊͷ৘ใʹม׵͞Ε·͢ɻ
  4. DrupalͷίʔσΟϯάن໿ ίʔσΟϯάن໿ͱ͸ – ίʔυͷॻ͖ํ΍ܗࣜͳͲɺ͞·͟·ͳܾ·ΓࣄΛఏࣔ͢ΔϓϩάϥϚ޲͚ͷҰ࿈ͷϧʔϧͰ͢ɻม਺΍ؔ਺ ͳͲͷ໋໊نଇɺېࢭࣄ߲ɺΠϯσϯτɺεϖʔεɺׅހ΍ԋࢉࢠͳͲͷه߸ͷ഑ஔͷ࢓ํͳͲΛఆٛ͠·͢ɻ – ίʔυͷදه๏ΛίʔσΟϯάن໿ͱͯ͠౷Ұ͓ͯ͘͠ͱɺՄಡੑ΍อकੑ͕ߴ·Γɺ։ൃޮ཰͕޲্͠·͢ɻ – ओͳݺͼํɿCode StandardsɺCoding

    Standardsɺίʔυن໿ɺίʔσΟϯάϧʔϧɾɾ DrupalͷίʔσΟϯάن໿ – PEARίʔσΟϯάن໿͕ϕʔεͱͳ͍ͬͯ·͢ɻ – DrupalͷίʔσΟϯάن໿͸ίΞόʔδϣϯؔ܎ͳ͘ɺৗʹ࠷৽ͷίʔυن໿ʹै͏ඞཁ͕͋Γ·͢ɻ – PHPStorm΍VS CodeͰࣗಈతʹݕग़/੔ܗ͢Δศརͳπʔϧ͕ఏڙ͞Ε͍ͯ·͢ɻ
  5. DrupalίʔσΟϯάن໿ͷҰྫ – Πϯσϯτͱۭന – λϒͳ͠Ͱɺ2ͭͷεϖʔεͷΠϯσϯτΛ࢖༻ – ߦͷ࠷ޙʹۭനΛೖΕͳ͍ – ߦͷ௕͞ –

    80จࣈ͕໨҆ – ԋࢉࢠ – ԋࢉࢠʢ=, -, +, *, =>, . ͳͲʣ͸ৗʹ1ͭͷεϖʔεΛ͚ͭΔ – …etc https://www.drupal.org/docs/develop/standards/coding-standards
  6. – ίΞϞδϡʔϧ – DrupalͷίΞʹؚ·ΕΔϞδϡʔϧͰ͢ɻ 
 – ίϯτϦϏϡʔτϞδϡʔϧ – Drupal.orgͰެ։͞Ε͍ͯΔϞδϡʔϧͰ͢ɻ –

    https://www.drupal.org/project/project_module 
 – ΧελϜϞδϡʔϧ – ϓϩδΣΫτͷͨΊʹಠࣗͰ։ൃ͢ΔϞδϡʔϧͰ͢ɻ Ϟδϡʔϧͷछྨ
  7. Ϟδϡʔϧͷछྨ - ίΞϞδϡʔϧ – Node – ίϯςϯπͷ࡞੒ɺฤूɺ࡟আɺઃఆɺදࣔΛ؅ཧ͠·͢ɻ – Block –

    ϖʔδΛߏ੒͢ΔϒϩοΫͷ഑ஔΛ੍ޚ͢ΔϞδϡʔϧͰ͢ɻ – Views – σʔλϕʔε͔ΒΧελϚΠζ͞ΕͨΫΤϦͱϦετΛੜ੒͠·͢ɻ – Media – ը૾ɺಈըͳͲͷϝσΟΞΞΠςϜͷ࡞੒ɺઃఆɺදࣔΛ؅ཧ͠·͢ɻ – Language – DrupalͷݴޠػೳΛѻ͏ͨΊͷجຊϞδϡʔϧͰ͢ɻϢʔβʔ͕ݴޠΛઃఆͯ͠ίϯςϯπʹద༻͢Δ͜ͱ͕Ͱ͖ ·͢ɻ – Workflows – Drupalͷίϯςϯπͷʮະެ։ʯʮެ։ࡁΈʯͷঢ়ଶΛ֦ு͠ɺίϯςϯπʹϞσϨʔγϣϯঢ়ଶΛఏڙ͠·͢ɻ – etc…
  8. Ϟδϡʔϧͷ৔ॴ your Drupal project root ᵓ── docroot │ ᵓ── core

    │ │ └── modules │ │ ᵓ── action │ │ ᵓ── aggregator │ │ ᵓ── … │ │ │ └── modules │ │ ᵓ── contrib │ │ └── custom … ɹɹɹɹɹ–––––––– ίΞϞδϡʔϧ͕഑ஔ͞ΕΔ ɹɹɹɹɹ–––––––– ίϯτϦϏϡʔτϞδϡʔϧ͕഑ஔ͞ΕΔ ɹɹɹɹɹ–––––––– ΧελϜϞδϡʔϧ͕഑ஔ͞ΕΔ ίΞϞδϡʔϧɺίϯτϦϏϡʔτϞδϡʔϧɺΧελϜϞδϡʔϧͰ 
 ϞδϡʔϧϑΝΠϧ܈Λ഑ஔ͢Δ৔ॴ͕ܾ·͍ͬͯ·͢ɻ
  9. ϞδϡʔϧͷσΟϨΫτϦߏ੒ʢҰྫʣ marucha ᵓ── config/ ᵓ── css/ ᵓ── js/ ᵓ── templates/

    ᵓ── src │ └── Controller │ └── HelloController.php ᵓ── tests/ ᵓ── marucha.info.yml ᵓ── marucha.module ᵓ── marucha.routing.yml ᵓ── marucha.services.yml … ϑΝΠϧͷΦʔτϩʔυͷͨΊ ʹɺσΟϨΫτϦߏ੒ʹϧʔϧ͕ ଘࡏ͢Δ
  10. ϞδϡʔϧͷϚγϯ໊ – Ϟδϡʔϧʹ͸ඞͣʮϚγϯ໊ʯ͕ଘࡏ͠·͢ɻ – DrupalίΞʹΑͬͯϓϩάϥϜͰϞδϡʔϧΛࢀর͢ΔͨΊʹ಺ ෦తʹ࢖༻͞Ε·͢ɻ – ӈͷྫͰ͸ʮmaruchaʯ͕Ϛγϯ໊Ͱ͢ɻ – marucha.info.ymlͳͲɺϑΝΠϧ໊ʹϚγϯؚ໊͕·ΕΔΑ͏ͳ

    ໋໊نଇΛ࣋ͭϑΝΠϧ͕ଘࡏ͠·͢ɻ 
 – Ϛγϯ໊ͷ໋໊نଇ – จࣈͰ࢝·Δඞཁ͕͋Γ·͢ɻ – খจࣈͱΞϯμʔείΞͷΈΛؚΊΔඞཁ͕͋Γ·͢ɻ – εϖʔεΛؚΊΔ͜ͱ͸Ͱ͖·ͤΜɻ – 50จࣈΛ௒͑ͯ͸ͳΓ·ͤΜɻ – γεςϜ಺ͰҰҙͰ͋Δඞཁ͕͋Γ·͢ɻαΠτͰ࢖༻͢ΔଞͷϞδϡʔϧɺ ςʔϚɺςʔϚΤϯδϯɺΠϯετʔϧϓϩϑΝΠϧͱಉ໊͡લΛ෇͚ͳ͍Ͱ͘ ͍ͩ͞ɻ – ༧໿ࡁΈͷ༻ޠ͸࢖༻Ͱ͖·ͤΜɿsrcɺlibɺvendorɺassetsɺcssɺfilesɺ imagesɺjsɺmiscɺtemplatesɺincludesɺfixturesɺdrupal marucha ᵓ── config │ └── install │ └── marucha.settings.yml ᵓ── css/ ᵓ── js/ ᵓ── templates/ ᵓ── src │ └── Controller │ └── HelloController.php ᵓ── tests/ ᵓ── marucha.info.yml ᵓ── marucha.module ᵓ── marucha.routing.yml ᵓ── marucha.services.yml …
  11. Drupal؀ڥͷ༻ҙ – Drupal 9ͷֶश؀ڥΛ༻ҙ – ༗໊ͳDrupalͷϩʔΧϧ։ൃ؀ڥߏஙπʔϧ – Lando – Docksal

    – DDEV – Drupal VM 
 – ࠓճ͸ྫͱͯ͠ɺLandoͰDrupal 9؀ڥΛߏங͢ΔखॱΛ঺հ
  12. LandoΛ༻͍ͨDrupalͷϩʔΧϧ։ൃ؀ڥͷ࡞੒ ͦͷ1. DrupalϓϩδΣΫτ࡞੒ʙίϯςφͷىಈ # ࡞ۀσΟϨΫτϦͷ࡞੒ͱҠಈ $ mkdir my-drupal9-app && cd

    my-drupal9-app # LandoͷॳظԽ $ lando init --source cwd --recipe drupal9 --webroot web --name my-drupal9-app # ίϯςφͷىಈ $ lando start …(লུ)... APPSERVER URLS https://localhost:55017 http://localhost:55018 http://my-drupal9-app.lndo.site:8080/ https://my-drupal9-app.lndo.site/ # DrupalϓϩδΣΫτͷ࡞੒ $ lando composer create-project drupal/recommended-project tmp && cp -r tmp/. . && rm -rf tmp
  13. ͦͷ2. DrupalͷΠϯετʔϧ – ϒϥ΢βͰϩʔΧϧαʔόʔʹΞΫηε͠·͢ɻ – http://my-drupal9-app.lndo.site:8080/ – ΠϯλϥΫςΟϒΠϯετʔϥʔ͕ىಈ͠·͢ɻ – ϓϩϑΝΠϧ͸ʮඪ४ʯΛબ୒

    – σʔλϕʔεͷ઀ଓઌ৘ใ͸ 
 lando info ίϚϯυͰ֬ೝ LandoΛ༻͍ͨDrupalͷϩʔΧϧ։ൃ؀ڥͷ࡞੒ ͓·͚ɿLandoͷૢ࡞ – lando stop – ίϯςφͷఀࢭ – lando ssh – ίϯςφͷγΣϧʹΞΫηε͢Δ
  14. ΞδΣϯμ 1. Ϟδϡʔϧͱ͸ 2. Ϟδϡʔϧ։ൃͷલఏ஌ࣝ 3. Ϟδϡʔϧͷछྨ 4. Ϟδϡʔϧͷ؅ཧ 5.

    ϞδϡʔϧͷσΟϨΫτϦߏ੒ͱϑΝΠϧ 6. Drupal؀ڥͷ༻ҙ 7. ࿅श໰୊