Errors with layout builder cont.

Created on 12 August 2023, 11 months ago
Updated 22 November 2023, 7 months ago

Iโ€™m running D9.5.10 (PHP 8.1.21) and installed Juicebox, then tried to change a display of an existing gallery to Juicebox but got

Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::get() in Drupal\juicebox\Plugin\views\style\JuiceboxDisplayStyle->confGetFieldSources() (line 454 of mysite\web\modules\contrib\juicebox\src\Plugin\views\style\JuiceboxDisplayStyle.php)

Thinking it might have a problem with the gallery I created a new test view with only Media image fields and titles belonging to filtered nodes, but I couldnโ€™t place the block with layout builder, it just hung after I hit Save. Going back, even after clearing caches, and clicking on Manage layout I get

The website encountered an unexpected error. Please try again later.
Error: Call to undefined method Drupal\Core\Field\BaseFieldDefinition::get() in Drupal\juicebox\Plugin\views\style\JuiceboxDisplayStyle->confGetFieldSources() (line 454 of modules\contrib\juicebox\src\Plugin\views\style\JuiceboxDisplayStyle.php).

Then I added a page display to the same test view, but on visiting the page I get

The website encountered an unexpected error. Please try again later.
TypeError: Exception::__construct(): Argument #2 ($code) must be of type int, array given in Exception->__construct() (line 368 of modules\contrib\juicebox\src\Plugin\views\style\JuiceboxDisplayStyle.php).

Meanwhile, the warning on the view,

โ€œTo ensure a fully functional Juicebox gallery please remember to add at least one field of type Image, File or File ID to your Juicebox view display, and to configure all Juicebox Gallery format settings. Once you have completed these steps, re-save your view to remove this warning.โ€

doesnโ€™t go away after I hit save. Is it possible Juicebox is not designed to work with media image fields referenced by content items in a view? Iโ€™m using fields, not rendering the content items.

๐Ÿ› Bug report
Status

Active

Version

4.0

Component

Code

Created by

๐Ÿ‡ญ๐Ÿ‡บHungary Grabby

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

Comments & Activities

  • Issue created by @Grabby
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Iโ€™m running D9.5.10 (PHP 8.1.21) and installed Juicebox, then tried to change a display of an existing gallery to Juicebox but got

    So, first you had a "gallery" then you installed Juicebox? It appears that way from #1. I have to ask "what gallery". How was the gallery created. A "Juicebox" gallery has a specific definition and meaning. Usually it is contained in a xml file that lists the images and thumbnails to be displayed in the gallery together with a set of options governing how they are displayed. The xml file is embedded in a content item according to instructions that are contained in or referenced on the overall Juicebox Project page. A Juicebox Javascript file processes this XML file and displays the gallery. If the gallery file doesn't meet the Javascript file's "expectations" the results are not likely to be happy ones.

    Juicebox was mostly built between 2013 and 2015 by the project's owner. This was before either the layout builder and media module were built. It is therefore not surprising that there may be problems using media or the layout module.

    Have to run, but just inserted a media item in a Gallery. Not sure how this works with layout builder. I will follow up.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Sorry for the "hit and run" response yesterday. On my live site I can view media items that are part of a Juicebox Gallery that is in turn part of a content type set up specifically to include such items. So, in a limited sense, media items will work with Juicebox.

    However your problem report in #1 indicates more substantial problems in the JuiceboxDisplayStyle.php program. Looking at the code in PHPStorm validates these concerns. The function create:

     public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
        // Create a new instance of the plugin. This also allows us to extract
        // services from the container and inject them into our plugin via its own
        // constructor as needed.
        return new static($configuration, $plugin_id, $plugin_definition, $container->get('entity_type.manager'), $container->get('entity_field.manager'), $container->get('link_generator'), $container->get('string_translation'), $container->get('request_stack'), $container->get('juicebox.formatter'));
      }

    appears to be be riddled with mistakes and will take some work. The same level of expertise that was needed to get JuiceboxFormatter.php working will probably be needed here.

  • ๐Ÿ‡ญ๐Ÿ‡บHungary Grabby

    Thanks for your quick attention to this issue. Iโ€™m sorry to hear it is such an involved problem. I canโ€™t help fix it, but I will do my share of testing when the time comes!

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Thanks for your patience @Grabby.

    I am looking into the whole chain of programs leading to JuiceboxDisplayStyle.php as well as that program itself. This chain is found in the /src directory underneath the main Juicebox directory and in two specific subdirectories there: Plugin and Controller. JuiceboxDisplayStyle is in the views subfolder under Plugin.

    It doesn't look like this whole area of code has been touched in years. Just for instance there is:

    watchdog_exception('juicebox', $e, $message);

    in JuiceboXmlControllerBase which references a function that is deprecated in Drupal 10.1. The same deprecated function is present in the JuiceboxDisplayStyle.php program and needs to be replaced going forward.

    I'm pretty sure that this whole chain of programs needs review. JuiceboxDisplayStyle is "at the end" of a chain of programs and won't work properly if the programs it depends on don't work properly. The create(ContainerInterface ...) function I referenced in #3 won't work unless programs above it in the dependency chain work properly. I suspect that these problems also affect issue 3372033 and that if we can fix JuiceboxDisplayStyle and the programs it depends on properly we may have more luck with 3372033.

    More to come. If community members with more expertise want to chip in they are most welcome. Such contributions got us a long ways with fixing the JuiceboxFormatter.php problems this Summer.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Status report: Sunday morning 8/27/2023. Slowly cranking my way through JuiceboxDisplayStyle.php, There are quite a number of errors in it. Or so it appears to my inexperienced eyes. If this program doesn't work properly and completely then we will see the errors reported in this issue and issue 3372033.

    Functionally ... and I am open to correction or clarification on this ... but functionally I think what is going on is:

    Juicebox was originally built on a plan to built galleries using the separate Juicebox Builder Pro program (that runs on Windows or Mac) then upload them to the sites/ directory, then embed them in a Drupal Content type, then process them through the Juicebox JS program (again acquired separately). A facility was added later to allow Galleries of image files to be displayed through Drupal's View Module. These image files are inserted into a Drupal content type and can use Juicebox type formattting. The JuiceboxDisplayStyle program is at the center of a few programs that are used to accomplish this second approach. If it doesn't work properly then this type of Gallery won't work properly. This becomes more apparent when you start using Drupal modules such as media and layout.

    Probably within a week or so I may be able to verify this. I think I can say pretty positively that the current version of the program is very incomplete.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Further update: finding a bunch of "params" that don't have leading slash where they are needed. Leads to undefined namespaces and unfound classes.

    e.g.

       * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
       *   The entity type manager.
       * @param \Drupal\Core\Utility\LinkGeneratorInterface $link_generator
       *    The link generator.

    where the \ was left off the @param before "Drupal" line 108 in JuiceboxDisplayStyle.php (and the following line). Or even more significantly

       * @param \Drupal\juicebox\JuiceboxGalleryInterface $gallery
       *   An initialized Juicebox gallery object.

    at line 59 of JuiceboxFormatterinterface.php. Without the \ you just get an undefined namespace for Drupal\juicebox. Unless I'm wrong, this plays havoc with the reliability of the code.

    Still I'm working toward a local copy of the code that actually works properly.

    I

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Stuck inside of mobile with the Memphis Blues again.

    Getting JuiceboxDisplayStyle.php working is beyond my current expertise level. Basically, it appears the class:

    class JuiceboxDisplayStyle extends StylePluginBase {

    near the top of the program never loads properly. There seems to need to be a program in the core views directory for Juicebox to communicate with. There are other examples in the core modules directory e.g., web/core/modules/views/src/Plugin/views/style/HtmlList.php
    or web/core/modules/views/src/Plugin/views/style/EntityReference.php

    which those modules use. Juicebox doesn't seem to have one. There is a comment and "link" just before class JuiceboxDisplayStyle is declared:

    /**
     * Plugin implementation of the 'juicebox' display style.
     *
     * @ingroup views_style_plugins
     *
     * @ViewsStyle(
     *
     *   id = "juicebox",
     *   title = @Translation("Juicebox Gallery"),
     *   help = @Translation("Display rows as a Juicebox Gallery."),
     *   theme = "views_view_list",
     *   display_types = {"normal"}
     * )
     */

    I'd infer that we might need something in the core views directory for Juicebox to link to. But I don't understand how this works and the documentation on Drupal.org is less than helpful.

    I think that the namespace at the top of the program has to be:

    namespace Drupal\views\Plugin\views\style;

    and not

    namespace Drupal\juicebox\Plugin\views\style;

    but what do I know?

    Expert help needed.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Trying to work through this. With a block set up with two images in a content type I named "Quick Juicebox" (the only other content in an instance of this content type is a Title) errors are generated in the function named newGallery in juiceboxformatter.php. The code generating the error (commented out in my test system right now) is:

       // Calculate the class that needs to be instantiated allowing modules to
        // alter the result.
        $class = 'Drupal\juicebox\JuiceboxFormatter';
        $this->moduleManager->alter('juicebox_gallery_class', $class, $library);
        // Instantiate the Juicebox gallery objects.
        $object_settings = [
          'filter_markup' => $this->configFactory->get('juicebox.settings')->get('apply_markup_filter'),
          'process_attributes' => FALSE,
        ];
        //var_dump($object_settings);
        //$gallery = new $class($id, $object_settings);
        //var_dump($gallery);
        //if ($gallery instanceof JuiceboxGalleryInterface) {
        //  return $gallery;
        // }
        //throw new \Exception('Could not instantiate Juicebox gallery.  ');
      }

    Somehow when the new gallery is "instantiated" in "gallery = new($class($id, $object_settings);" the juiceboxformatter.php program runs and thinks that the variable $config_factory is a string and kicks off an error. It is supposed to send a gallery object to:

    "TypeError: Drupal\juicebox\Plugin\Field\FieldFormatter\JuiceboxFieldFormatter::buildGallery(): Argument #1 ($gallery) must be of type Drupal\juicebox\JuiceboxGalleryInterface, null given, called in D:\webpage\compg_2\web\modules\contrib\juicebox\src\Plugin\Field\FieldFormatter\JuiceboxFieldFormatter.php on line 263 in Drupal\juicebox\Plugin\Field\FieldFormatter\JuiceboxFieldFormatter->buildGallery() (line 284 of modules\contrib\juicebox\src\Plugin\Field\FieldFormatter\JuiceboxFieldFormatter.php)."

    the JuiceboxFieldFormatter.php program. But it doesn't because juiceboxformatter.php doesn't process it correctly.

    The point of all this, from a big picture perspective, is that you are supposed to be able to create a juicebox gallery content item just by sticking images into a content type and formattting them with Juicebox. The content item would then be run through the Juicebox Javascript code just like an uploaded gallery constructed by JuiceboxBuilderPro would be.

    This doesn't work right now.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Not to beat a dead horse but;

    Here is the code for the newgallery function with some var_dumps inserted

      public function newGallery(array $id_args) {
        // Calculate the gallery ID.
        $id = '';
        foreach ($id_args as $arg) {
          if (is_string($arg)) {
            // Drop special characters in individual args and delimit by double-dash.
            $arg = preg_replace('/[^0-9a-zA-Z-]/', '-', $arg);
            $id .= $arg . '--';
          }
        }
        $id = trim($id, '- ');
        // Get the library data. We do this early (before instantiating) as the lib
        // details should be allowed to impact which classes are used.
        $library = $this->getLibrary();
        // Calculate the class that needs to be instantiated allowing modules to
        // alter the result.
        $class = 'Drupal\juicebox\JuiceboxFormatter';
        var_dump($class);
        $this->moduleManager->alter('juicebox_gallery_class', $class, $library);
        // Instantiate the Juicebox gallery objects.
        var_dump($class);
        $object_settings = [
          'filter_markup' => $this->configFactory->get('juicebox.settings')->get('apply_markup_filter'),
          'process_attributes' => FALSE,
        ];
        var_dump($object_settings);
        $gallery = new $class($id, $object_settings);
        if ($gallery instanceof JuiceboxGalleryInterface) {
          return $gallery;
        }
        throw new \Exception('Could not instantiate Juicebox gallery.  ');
      }

    And here is the output on my test system:

    D:\webpage\compg_2\web\modules\contrib\juicebox\src\JuiceboxFormatter.php:190:string 'Drupal\juicebox\JuiceboxFormatter' (length=33)
    D:\webpage\compg_2\web\modules\contrib\juicebox\src\JuiceboxFormatter.php:193:string 'Drupal\juicebox\JuiceboxFormatter' (length=33)
    D:\webpage\compg_2\web\modules\contrib\juicebox\src\JuiceboxFormatter.php:198:
    array (size=2)
    'filter_markup' => boolean true
    'process_attributes' => boolean false
    The website encountered an unexpected error. Please try again later.

    TypeError: Drupal\juicebox\JuiceboxFormatter::__construct(): Argument #1 ($config_factory) must be of type Drupal\Core\Config\ConfigFactoryInterface, string given, called in D:\webpage\compg_2\web\modules\contrib\juicebox\src\JuiceboxFormatter.php on line 199 in Drupal\juicebox\JuiceboxFormatter->__construct() (line 116 of modules\contrib\juicebox\src\JuiceboxFormatter.php).

    The class variable is not modified by the module_manager ... which is probably fine. But when the $gallery variable is instantiated, it runs JuiceboxFormatter.php and kicks off an error that I don't comprehend. $config_factory should be of type ConfigFactoryInterface according to the code in JuiceboxFormatter. The TypeError brings everything to a screeching halt.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Some progress with going back and forth between the 4.0.0 version of JuiceboxFormatter and my test version of JuiceboxDisplayStyle. At least I've found a combination that eliminated the __construct() argument bug within JuiceboxFormatter. I can display my "Quick Juicebox" content type page on my test system. Just two images right now but that's a start. I don't think I'm properly constructing a true Juicebox Gallery through JuiceboxDisplaystyle yet but further testing will tell.

    FWIW JuiceboxDisplaystyle calls the newGallery function that's within JuiceboxFormatter and at least that part seems to work properly now.

    More to come.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States fkelly

    Finally nailed what seemed to be an intermittent and inconsistent "bug" in JuiceboxFormatter.php and its construct function. The fixes to JuiceboxFormatter that were incorporated into the 4.0.x release and also into the 4.0.x-dev release (which included a separate patch file) included modifications to the juicebox.services.yml file. This file provides a list of arguments, representing services, that get fed into the construct function of JuiceboxFormatter. Luke kindly provided a juicebox.post.update php file that clears cache when juicebox is updated through composer. If the post.update program is not run, then a table named cache_container will still contain obsolete service "links" that will foul up the construct argument. There is a work around to use

    drush ev "drupal_flush_all_caches();"
    followed by drush cr

    to flush the same cache. You can do this even if you have not run a composer update ... for instance I am just modifying my code in PHPstorm for my local Wampserver. For a couple of days I was looking at fouled up code in my test Wampserver with the same code running fine on my hosted "production" system (where I had run the updates through composer).

    There are several posts on Drupal and in StackOverflow and elsewhere discussing the inadequate documentation of hook_update. That's another discussion entirely and a diversion from fixing up Juicebox for Drupal 10.

    I am partly along the way towards fixing up things relating to the layout builder and displaystyle issues. I can create a custom content type, insert some images and use Juiceboxgallery formatting to display them as galleries in a block built through layout builder. I suspect that all the "newgallery" and associated functions in juiceboxdisplaystyle need some work and I know that there is a deprecated function (watchdog_exception) in several of the programs in Juicebox. Plus there are still standards fixes and general cleanup to be done.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Luke.Leber Pennsylvania

    Quite a bit to unpack here :D. Thanks for the bugs.

    TypeError: Exception::__construct(): Argument #2 ($code) must be of type int, array given in Exception->__construct() (line 368 of modules\contrib\juicebox\src\Plugin\views\style\JuiceboxDisplayStyle.php).

    This one makes sense! It looks like the module is sort of half-implementing a translation here:

    throw new \Exception('Empty or invalid field source @source detected for Juicebox view-based gallery.', ['@source' => $source_field]);

    Luckily, Drupal's coding guidelines says that we should not translate exception messages, so this can be resolved simply via
    throw new \Exception('Empty or invalid field source ' . $source_field . ' detected for Juicebox view-based gallery.');

    --

    For the other ones, it would be really awesome if someone could upload the configuration for the view that was causing the snag.

Production build 0.69.0 2024