単なる失敗の記録になってしまいました。
こんなの載せて意味あるのかなと思いつつ・・・
別途開発を模索しているアプリ向けに、位置情報を含むデータ整備を行って、APIで提供したい。
そのためのAPIを自前で開発するのではなく、ヘッドレスCMS向けAPI提供に強いと言われる Drupal を活用すれば、素早く高品質なAPIを実装できるのではないか、という試みです。
Drupal 内で地図アプリ実現
まずは、Drupal内で地図アプリを実装してみよう。
Drupal9 で断念した、こちらを参照して同じことをやってみます。
機能拡張のインストール(失敗編)
※これはやはりだめだったので、成功編は次の章へ(と思ったらやはりだめでした・・・)
まずは
- Simple Google Maps
- Geolocation Field
- Geocoder
- IP Geolocation Views & Maps
をインストール
やはりだめだった・・・
Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /opt/drupal/web/modules/ip_geoloc/src/Services/IpGeoLocViewsPluginStyle.php on line 556
Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated. Use either `(a ? b : c) ? d : e` or `a ? b : (c ? d : e)` in /opt/drupal/web/modules/ip_geoloc/src/Plugin/views/style/ip_geoloc_plugin_style.inc on line 451
Fatal error: Could not check compatibility between Drupal\ip_geoloc\Plugin\views\style\IpGeoLocPluginStyleOpenLayers::create(Drupal\ip_geoloc\Plugin\views\style\ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) and Drupal\views\Plugin\views\PluginBase::create(Symfony\Component\DependencyInjection\ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition), because class Drupal\ip_geoloc\Plugin\views\style\ContainerInterface is not available in /opt/drupal/web/modules/ip_geoloc/src/Plugin/views/style/IpGeoLocPluginStyleOpenLayers.php on line 50
モジュール Simple Google Maps が有効化されました。
3 個の翻訳ファイルをインポートしました。9 個の翻訳を追加し、18 個の翻訳を更新、0 個の翻訳を削除しました。
これはOK。
モジュール Geolocation が有効化されました。
3 個の翻訳ファイルをインポートしました。171 個の翻訳を追加し、255 個の翻訳を更新、0 個の翻訳を削除しました。
OK。
モジュール Geocoder が有効化されました。
3 個の翻訳ファイルをインポートしました。7 個の翻訳を追加し、57 個の翻訳を更新、0 個の翻訳を削除しました。
先程エラーになった「IP Geolocation Views & Maps」はチェックがついているので、インストールされていることになっている。deprecated=非推奨だから、インストール自体はできるということか。
コンテンツタイプ作成
サイト/admin/structure/types/add
で、コンテンツタイプの追加、フィールド追加。
フィールドタイプは Geolocation で登録できているけど、ウィジェットタイプの指定ができない・・・
Drupal7 から変更になってますかね。
こちらを参照。
まず、この辺、というか「geocoder_field」「geocoder_address」を有効にしないといけないようだけど、geocoder_addressは有効にできないので、まずはgeocoder_field。
そうすると、フィールドの編集画面が変わる。
が、その前に、Geocoderの設定。
サイト/admin/config/system/geocoder
で、Providers を設定するはずですが、エラー。
The website encountered an unexpected error. Please try again later.
これじゃ分からない。
ログを詳細化。
サイト/admin/config/development/logging
The website encountered an unexpected error. Please try again later.
Error: Class 'Geocoder\Provider\AbstractProvider' not found in include() (line 20 of modules/geocoder/modules/geocoder_field/src/Geocoder/Provider/File.php).
この辺を見ると、addressとgeofieldという拡張が必要なんですかね・・・
Geofield をインストール、有効化。
Geocoder Geofield を有効化。
だめですね・・・
composer と drush でやらないといけないのか?
こんな感じで、住所フィールドから連携させるはずなのですが・・・
いったん、上でインストールした機能拡張はアンインストールします。
一気にはできないので、できるものから。
途中エラー・・・
Notice: Undefined index: table in Drupal\views\Plugin\ViewsHandlerManager->getHandler() (line 82 of core/modules/views/src/Plugin/ViewsHandlerManager.php).
Notice: Undefined index: table in Drupal\views\Plugin\ViewsHandlerManager->getHandler() (line 82 of core/modules/views/src/Plugin/ViewsHandlerManager.php).
しかし、アンインストールは継続できるので、そのまま継続。
そうしたら、504エラーでサイトが止まってしまった・・・
サーバごと再起動したら、とりあえずアンインストールもできていました。
Leaflet モジュールを使う(やはり失敗編)
もう少し新しい情報が欲しいと思ってみていたら、Leaflet が良さそうな気がする。
こちらのドキュメントを見ながら使ってみます。
インストール
インストールは、in the usual way でというだけでホッとする。(と思ったけど・・・)
4 個のモジュールが有効化されました: Geofield, Leaflet, Leaflet Markercluster, Leaflet Views 。
6 個の翻訳ファイルをインポートしました。37 個の翻訳を追加し、201 個の翻訳を更新、0 個の翻訳を削除しました。
けど、Leaflet JavaScript library はダウンロードして、配置しないといけないんですね。
unzip入っていなかったりして、そこからになってしまいましたが、配置しました。
geoPHPも必要。
入れないとエラー
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class '\geoPHP' not found in Drupal\geofield\GeoPHP\GeoPHPWrapper->getAdapterMap() (line 33 of modules/geofield/src/GeoPHP/GeoPHPWrapper.php).
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class '\geoPHP' not found in Drupal\geofield\GeoPHP\GeoPHPWrapper->getAdapterMap() (line 33 of modules/geofield/src/GeoPHP/GeoPHPWrapper.php).
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class '\geoPHP' not found in Drupal\geofield\GeoPHP\GeoPHPWrapper->getAdapterMap() (line 33 of modules/geofield/src/GeoPHP/GeoPHPWrapper.php).
モジュールだけでなく、ライブラリを別途ダウンロードして配置。
Drupal は、こういうパターンが多いのか・・・
しかし、だめ。
Warning: call_user_func_array() expects parameter 1 to be a valid callback, class '\geoPHP' not found in Drupal\geofield\GeoPHP\GeoPHPWrapper->getAdapterMap() (line 33 of modules/geofield/src/GeoPHP/GeoPHPWrapper.php).
Warning: array_keys() expects parameter 1 to be array, null given in Drupal\geofield\Plugin\Field\FieldFormatter\GeofieldDefaultFormatter->getOutputFormat() (line 109 of modules/geofield/src/Plugin/Field/FieldFormatter/GeofieldDefaultFormatter.php).
Warning: in_array() expects parameter 2 to be array, null given in Drupal\geofield\Plugin\Field\FieldFormatter\GeofieldDefaultFormatter->getOutputFormat() (line 109 of modules/geofield/src/Plugin/Field/FieldFormatter/GeofieldDefaultFormatter.php).
Warning: array_keys() expects parameter 1 to be array, null given in Drupal\geofield\Plugin\Field\FieldFormatter\GeofieldDefaultFormatter->getOutputFormat() (line 109 of modules/geofield/src/Plugin/Field/FieldFormatter/GeofieldDefaultFormatter.php).
Warning: in_array() expects parameter 2 to be array, null given in Drupal\geofield\Plugin\Field\FieldFormatter\GeofieldDefaultFormatter->getOutputFormat() (line 109 of modules/geofield/src/Plugin/Field/FieldFormatter/GeofieldDefaultFormatter.php).
断念・・・