I have a scenario where I need to display a list of paragraphs, which I know views supports.

But I need to group them by Bundle name, which is working, except for the title.

Here are the steps I took to repoduce:

1. Create 2 separate bundles, in this case they are called Material Safety Data Sheet (MSDS) (machine name: msds_sheet) and Special Local Need (SLN) Label (machine name: sln_label)

Paragraphs Bundles

2. Create a view to display Pragraph Items with fields, and add the fields needed as well as the field "Paragraphs item: Bundle"

Paragraphs Views setup

Paragraphs Views group setup

3. Once saved, you can see the output of the bundle type is incorrect, it should say Material Safety Data Sheet (MSDS) but instead it says Paragraphs bundle msds_sheet

Paragraphs Views preview

Paragraphs Views output

Am I doing something wrong? There is an option to "Output machine name" but this only shows the machine name (e.g msds_sheet) and doesn't do what I expect with it turned off.

Please help!

Comments

capfive created an issue. See original summary.

capfive’s picture

Anyone able to help with this?

capfive’s picture

I took a look at this myself, and I am not in anyway a coder but these are the steps I took to fix the issue.

I went to this page
Paragraphs Bundles
and noticed that the bundle name is displayed correctly, so I found the code that produces this name

<?php
function paragraphs_admin_bundle_overview() {
  $page = array();
  $bundles = paragraphs_bundle_load();
  $field_ui = module_exists('field_ui');

  $header = array(
    t('Bundle name'),
    array('data' => t('Operations'), 'colspan' => $field_ui ? '4' : '2')
  );
  $rows = array();
  foreach ($bundles as $bundle) {

    $type_url_str = strtr($bundle->bundle, array('_' => '-'));

    $row = array(
      array(
        'data' => $bundle->name . ' (' . $bundle->bundle . ')',
      )
    );
...
?>

Particularly the

<?php $bundle->name ?> part and I inserted it where the module prints the incorrect title.

Which is found in /paragraphs/paragraphs.module line 132
<code>
<?php
  foreach ($bundles as $machine_name => $bundle) {
    $return['paragraphs_item']['bundles'][$bundle->bundle] = array(
      'label' => t('Paragraphs bundle @bundle', array('@bundle' => $bundle->bundle)),
      'admin' => array(
        'path' => 'admin/structure/paragraphs/%paragraphs_bundle',
        'real path' => 'admin/structure/paragraphs/' . strtr($machine_name, array('_' => '-')),
        'bundle argument' => 3,
        'access arguments' => array('administer paragraphs bundles'),
      ),
    );
  }
?>

I changed <?php 'label' => t('Paragraphs bundle @bundle', array('@bundle' => $bundle->bundle)), ?> to <?php 'label' => t('@bundle', array('@bundle' => $bundle->name)), ?> and it is now fixed

This is the correct code that has now fixed this problem for me

<?php
  foreach ($bundles as $machine_name => $bundle) {
    $return['paragraphs_item']['bundles'][$bundle->bundle] = array(
      'label' => t('@bundle', array('@bundle' => $bundle->name)),
      'admin' => array(
        'path' => 'admin/structure/paragraphs/%paragraphs_bundle',
        'real path' => 'admin/structure/paragraphs/' . strtr($machine_name, array('_' => '-')),
        'bundle argument' => 3,
        'access arguments' => array('administer paragraphs bundles'),
      ),
    );
  }
?>

I don't know how to create a diff patch :( if someone would like to assist (if what I did was correct) then that would be great :)

jeroen.b’s picture

Status: Active » Needs review
Issue tags: +drupaldevdays
StatusFileSize
new631 bytes

Could you try this patch?

rossington350’s picture

Issue tags: -drupaldevdays

I can confirm this fixed the issue for me.

capfive’s picture

Status: Needs review » Reviewed & tested by the community

sorry didnt even see the patch comment!

I can confirm it has fixed for me too :) thanks for the help!

pol’s picture

Thanks, this has fixed the issue too. RTBC+1

  • jeroen.b committed dd8da31 on 7.x-1.x
    Issue #2592021 by jeroen.b, capfive: Views Paragraphs item: Bundle doesn...
jeroen.b’s picture

Status: Reviewed & tested by the community » Fixed

Thanks! Pushed!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.