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

Drupal8 State API と Configuration API

Drupal8 State API と Configuration API

Drupal8のVariables~State API と Configuration API ~

kazukomurata

January 26, 2017
Tweet

More Decks by kazukomurata

Other Decks in Programming

Transcript

  1. State API ίʔυྫ // Set. \Drupal::state()->set('key', value); ※key͸Ϟδϡʔϧ໊ͱkey໊শΛ ʮ.ʯͰͭͳ͛ͯࢦఆ͢Δ(ex. system.css_js_query_string)

    // Get. \Drupal::state()->get('key'); // Delete. \Drupal::state()->delete(‘key'); Service ͰDI͢Δͱ͖͸ʮStateInterfaceʯͰड͚ࢭΊΔͷ͕ਖ਼ղ(ͨͿΜ)
  2. Configuration API ίʔυྫ // Set. $config = \Drupal::service(‘config.factory') ->getEditable('system.performance'); $config->set('cache.page.enabled',

    1); // Get. $config = \Drupal::config('system.maintenance'); $message = $config->get('message'); // Delete. \Drupal::service(‘config.factory’)->getEditable('key')->delete();
  3. Configuration API ิ଍ ɾઃఆ஋ͷొ࿥ը໘͸ConfigFormBaseΛܧঝָͯ͠͠·͠ΐ ͏ɻ ྫ : core/modules/system/src/Form/SiteInformationForm.php ɾServiceར༻ͷ࣌͸ɺState APIಉ༷ɺConfigFactoryInterfaceͰ

    ड͚ࢭΊͭͭɺconstractͷதͰɺඞཁͳ෼Λget͠ͱ͘ͷ͕҆શ ͔΋ɻ public function __construct(ConfigFactoryInterface $config { $this->config = $config->get('key'); }