After updrade from D7 website : TypeError: Cannot access offset of type string on string in bootstrap\src\Plugin\Provider\DrupalBootstrapStyles.php

Created on 24 August 2022, almost 2 years ago
Updated 11 July 2023, 12 months ago

Hello,

I will try to bring as much information as possible about my problem. Thanks for helps !

Problem/Motivation

After an upgrade from a D7 website
New installation of Boostrap 8.x-3.25

I have added logs so line number is wrong for the file.

Line with bug (complete function bellow), $file['name'] doesn't exist because $file is a string :

if (strpos($file['name'], '/dist/' . $version . '/' . Bootstrap::PROJECT_BRANCH . '/') !== 0) {
TypeError: Cannot access offset of type string on string in Drupal\bootstrap\Plugin\Provider\DrupalBootstrapStyles->Drupal\bootstrap\Plugin\Provider\{closure}() (line 75 of D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\DrupalBootstrapStyles.php)
#0 [internal function]: Drupal\bootstrap\Plugin\Provider\DrupalBootstrapStyles->Drupal\bootstrap\Plugin\Provider\{closure}('/dist/css/boots...')
#1 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\DrupalBootstrapStyles.php(80): array_filter(Array, Object(Closure))
#2 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ApiProviderBase.php(333): Drupal\bootstrap\Plugin\Provider\DrupalBootstrapStyles->parseAssets(Array, 'bootstrap', '3.4.1', Object(Drupal\bootstrap\Plugin\Provider\CdnAssets))
#3 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ApiProviderBase.php(38): Drupal\bootstrap\Plugin\Provider\ApiProviderBase->requestApiAssets('bootstrap', '3.4.1', Object(Drupal\bootstrap\Plugin\Provider\CdnAssets))
#4 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ProviderBase.php(367): Drupal\bootstrap\Plugin\Provider\ApiProviderBase->discoverCdnThemes('3.4.1')
#5 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ProviderBase.php(172): Drupal\bootstrap\Plugin\Provider\ProviderBase->Drupal\bootstrap\Plugin\Provider\{closure}(Array)
#6 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ProviderBase.php(368): Drupal\bootstrap\Plugin\Provider\ProviderBase->cacheGet('themes', 'IFPYIBFR2zinuHC...', Array, Object(Closure))
#7 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ApiProviderBase.php(22): Drupal\bootstrap\Plugin\Provider\ProviderBase->getCdnThemes('3.4.1')
#8 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ProviderBase.php(296): Drupal\bootstrap\Plugin\Provider\ApiProviderBase->discoverCdnAssets('3.4.1', 'bootstrap')
#9 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ProviderBase.php(172): Drupal\bootstrap\Plugin\Provider\ProviderBase->Drupal\bootstrap\Plugin\Provider\{closure}(Array)
#10 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ProviderBase.php(297): Drupal\bootstrap\Plugin\Provider\ProviderBase->cacheGet('assets', 'Wa9BFfBHcrFr12d...', Array, Object(Closure))
#11 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ProviderBase.php(126): Drupal\bootstrap\Plugin\Provider\ProviderBase->getCdnAssets('3.4.1', 'bootstrap')
#12 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ProviderBase.php(172): Drupal\bootstrap\Plugin\Provider\ProviderBase->Drupal\bootstrap\Plugin\Provider\{closure}(Array)
#13 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Provider\ProviderBase.php(131): Drupal\bootstrap\Plugin\Provider\ProviderBase->cacheGet('library', 'Fam3dfpFl4CRFkp...', Array, Object(Closure))
#14 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Plugin\Alter\LibraryInfo.php(39): Drupal\bootstrap\Plugin\Provider\ProviderBase->alterFrameworkLibrary(Array)
#15 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\src\Bootstrap.php(303): Drupal\bootstrap\Plugin\Alter\LibraryInfo->alter(Array, 'bootstrap', NULL)
#16 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\themes\bootstrap\bootstrap.theme(100): Drupal\bootstrap\Bootstrap::alter('bootstrap_libra...', Array, 'bootstrap', NULL)
#17 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Theme\ThemeManager.php(449): bootstrap_library_info_alter(Array, 'bootstrap', NULL)
#18 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Theme\ThemeManager.php(458): Drupal\Core\Theme\ThemeManager->alterForTheme(Object(Drupal\Core\Theme\ActiveTheme), 'library_info', Array, 'bootstrap', NULL)
#19 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDiscoveryParser.php(375): Drupal\Core\Theme\ThemeManager->alter('library_info', Array, 'bootstrap')
#20 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDiscoveryParser.php(126): Drupal\Core\Asset\LibraryDiscoveryParser->parseLibraryInfo('bootstrap', 'themes/bootstra...')
#21 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDiscoveryCollector.php(87): Drupal\Core\Asset\LibraryDiscoveryParser->buildByExtension('bootstrap')
#22 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDiscoveryCollector.php(66): Drupal\Core\Asset\LibraryDiscoveryCollector->getLibraryDefinitions('bootstrap')
#23 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Cache\CacheCollector.php(149): Drupal\Core\Asset\LibraryDiscoveryCollector->resolveCacheMiss('bootstrap')
#24 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDiscoveryCollector.php(149): Drupal\Core\Cache\CacheCollector->get('bootstrap')
#25 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDiscoveryCollector.php(111): Drupal\Core\Asset\LibraryDiscoveryCollector->applyLibrariesExtend('core', 'drupal.ajax', Array)
#26 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDiscoveryCollector.php(66): Drupal\Core\Asset\LibraryDiscoveryCollector->getLibraryDefinitions('core')
#27 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Cache\CacheCollector.php(149): Drupal\Core\Asset\LibraryDiscoveryCollector->resolveCacheMiss('core')
#28 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDiscovery.php(44): Drupal\Core\Cache\CacheCollector->get('core')
#29 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDiscovery.php(58): Drupal\Core\Asset\LibraryDiscovery->getLibrariesByExtension('core')
#30 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDependencyResolver.php(68): Drupal\Core\Asset\LibraryDiscovery->getLibraryByName('core', 'jquery')
#31 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDependencyResolver.php(70): Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies(Array, Array)
#32 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\LibraryDependencyResolver.php(41): Drupal\Core\Asset\LibraryDependencyResolver->doGetDependencies(Array)
#33 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\AssetResolver.php(104): Drupal\Core\Asset\LibraryDependencyResolver->getLibrariesWithDependencies(Array)
#34 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Asset\AssetResolver.php(116): Drupal\Core\Asset\AssetResolver->getLibrariesToLoad(Object(Drupal\Core\Asset\AttachedAssets))
#35 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Render\HtmlResponseAttachmentsProcessor.php(312): Drupal\Core\Asset\AssetResolver->getCssAssets(Object(Drupal\Core\Asset\AttachedAssets), false)
#36 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\Render\HtmlResponseAttachmentsProcessor.php(158): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAssetLibraries(Object(Drupal\Core\Asset\AttachedAssets), Array)
#37 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\modules\big_pipe\src\Render\BigPipeResponseAttachmentsProcessor.php(94): Drupal\Core\Render\HtmlResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse))
#38 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\EventSubscriber\HtmlResponseSubscriber.php(45): Drupal\big_pipe\Render\BigPipeResponseAttachmentsProcessor->processAttachments(Object(Drupal\Core\Render\HtmlResponse))
#39 [internal function]: Drupal\Core\EventSubscriber\HtmlResponseSubscriber->onRespond(Object(Symfony\Component\HttpKernel\Event\ResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#40 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher.php(142): call_user_func(Array, Object(Symfony\Component\HttpKernel\Event\ResponseEvent), 'kernel.response', Object(Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher))
#41 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\vendor\symfony\http-kernel\HttpKernel.php(191): Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object(Symfony\Component\HttpKernel\Event\ResponseEvent), 'kernel.response')
#42 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\vendor\symfony\http-kernel\HttpKernel.php(137): Symfony\Component\HttpKernel\HttpKernel->filterResponse(Object(Drupal\Core\Render\HtmlResponse), Object(Symfony\Component\HttpFoundation\Request), 1)
#43 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\vendor\symfony\http-kernel\HttpKernel.php(80): Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object(Symfony\Component\HttpFoundation\Request), 1)
#44 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\StackMiddleware\Session.php(58): Symfony\Component\HttpKernel\HttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#45 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\StackMiddleware\KernelPreHandle.php(48): Drupal\Core\StackMiddleware\Session->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#46 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\modules\page_cache\src\StackMiddleware\PageCache.php(106): Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#47 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\modules\page_cache\src\StackMiddleware\PageCache.php(85): Drupal\page_cache\StackMiddleware\PageCache->pass(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#48 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\StackMiddleware\ReverseProxyMiddleware.php(48): Drupal\page_cache\StackMiddleware\PageCache->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#49 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\StackMiddleware\NegotiationMiddleware.php(51): Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#50 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\vendor\stack\builder\src\Stack\StackedHttpKernel.php(23): Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#51 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\core\lib\Drupal\Core\DrupalKernel.php(709): Stack\StackedHttpKernel->handle(Object(Symfony\Component\HttpFoundation\Request), 1, true)
#52 D:\wamp\www\d9-stagr-2022-08-20\httpdocs\web\index.php(19): Drupal\Core\DrupalKernel->handle(Object(Symfony\Component\HttpFoundation\Request))
#53 {main}
.

DrupalBootstrapStyles.php

I have added logs to view values, see comments.

protected function parseAssets(array $data, $library, $version, CdnAssets $assets = NULL) {
    if (!isset($assets)) {
      $assets = new CdnAssets();
    }

    $files = array_filter(isset($data['files']) ? $data['files'] : [], function ($file) use ($library, $version) {
      Drupal::logger('theme')->notice(json_encode($file)); // ""\/dist\/css\/bootstrap.css"" => It's a string so $file['name'] doesn't exist
      Drupal::logger('theme')->notice(json_encode($version)); // ""3.4.1""
      Drupal::logger('theme')->notice(json_encode(Bootstrap::PROJECT_BRANCH)); // ""8.x-3.x""
      if (strpos($file['name'], '/dist/' . $version . '/' . Bootstrap::PROJECT_BRANCH . '/') !== 0) {
        return FALSE;
      }
      $theme = !!preg_match("`drupal-bootstrap-([\w]+)(\.min)?\.css$`", $file['name']);
      return ($library === 'bootstrap' && !$theme) || ($library === 'bootswatch' && $theme);
    });

    foreach ($files as $file) {
      $assets->append($this->getCdnUrl('drupal-bootstrap-styles', $version, !empty($file['symlink']) ? $file['symlink'] : $file['name'], $file));
    }

    return $assets;
  }

I have the following message in bootstrap settings :
Unable to parse the jsDelivr API to determine available themes.

I'm on a local environnement (Wamp on windows). I'm thinking there are a problem to get external ressources and the theme can't handle this...

Sorry for my bad english...

šŸ› Bug report
Status

Fixed

Version

3.25

Component

Code

Created by

šŸ‡«šŸ‡·France olorin.fr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024