MWDelaney / sage-acf-wp-blocks

Composer library for generating ACF Gutenberg blocks from templates. Intended for use with Roots/Sage (http://roots.io)
347 stars 65 forks source link

Updating to v0.6 leads to error #52

Open djmtype opened 4 years ago

djmtype commented 4 years ago

After updating to sage-acf-wp-blocks from v0.5 to v0.6, WordPress throws an error. I haven't changed any of my blocks' syntax or location.

I also tried removing this block from my directory, but then I got the same error for the next block.

All my ACF blocks reside in ./resources/views/blocks directory like the sage-acf-gutenberg-blocks.php states

Fatal error: Uncaught InvalidArgumentException: View [views.blocks.alert] not found. in /Users/scottrod/Sites/maridose/wp-content/themes/maridose/vendor/illuminate/view/FileViewFinder.php:137 Stack trace: #0 /Users/scottrod/Sites/maridose/wp-content/themes/maridose/vendor/illuminate/view/FileViewFinder.php(79): Illuminate\View\FileViewFinder->findInPaths('views.blocks.al...', Array) #1 /Users/scottrod/Sites/maridose/wp-content/themes/maridose/vendor/illuminate/view/Factory.php(128): Illuminate\View\FileViewFinder->find('views.blocks.al...') #2 [internal function]: Illuminate\View\Factory->make('views.blocks.al...', Array, Array) #3 /Users/scottrod/Sites/maridose/wp-content/themes/maridose/vendor/roots/sage-lib/Template/Blade.php(138): call_user_func_array(Array, Array) #4 /Users/scottrod/Sites/maridose/wp-content/themes/maridose/vendor/roots/sage-lib/Template/Blade.php(58): Roots\Sage\Template\Blade->__call('make', Array) #5 /Users/scottrod/Sites/maridose/wp-content/themes/maridose/app/helpers.php(55): Roots\Sage\Template in /Users/scottrod/Sites/maridose/wp-content/themes/maridose/vendor/illuminate/view/FileViewFinder.php on line 137

My block

{{--
  Title: Alert
  Category: formatting
  Icon: megaphone
  PostTypes: page post
  SupportsAlign: false
  SupportsMode: true
  SupportsMultiple: true
  Mode: edit
--}}

@php
$classes = '';
$alert_class = '';
$alert_color = get_field('alert_color');
$alert_content = get_field('alert_content')
@endphp

@if( !empty($block['className']) ) 
    @php $classes .= sprintf( ' %s', $block['className'] ) @endphp
@endif

@if($alert_color == 'primary')
@php $alert_class = 'alert-primary' @endphp
@elseif ($alert_color == 'secondary')
@php $alert_class = 'alert-secondary' @endphp
@elseif ($alert_color == 'default')
@php $alert_class = 'alert-default' @endphp
@endif

<section class="alert {!! $alert_class !!} {!! $classes !!}">

<div class="container max-width-lg flow-xs-y">
        {!! $alert_content !!}
    </div>
    <!-- /.container -->

</section>
speakerbug commented 4 years ago

Just an FYI this is actually already opened as an issue #50 and there's a fix as a pull request #51 but it's been sitting for almost two weeks now.

blift commented 3 years ago

Hi I have aded pull request with fixed error, please verify

robmeijerink commented 3 years ago

@MWDelaney Some people are facing issues in Sage 9. Any chance you can merge the PR that fixes this?

blift commented 3 years ago

@MWDelaney and @robmeijerink please verify pull request #51 before merge, in my case still it not working on sage 9, I've added #53 pull request with update, but not tested with sage 10. The path result is the same in sage_blocks_callback method line 221, so should work properly.

syclone commented 3 years ago

Hi, I just installed this plugin and got the same error with v0.6. I decided to try v0.5 after reading through these issues and it worked fine. For anyone who is like me and looking for a workaround, v0.5 did the trick.

So just install it like so:

composer require mwdelaney/sage-acf-gutenberg-blocks:0.5

tombroucke commented 3 years ago

I have created a pull request that fixes this issue. In the meantime, you can fix the issue by updating the template() function in helpers.php:

function template($file, $data = [])
{
    if ( ! file_exists( $file ) && strpos( $file, 'views/blocks/' ) !== false ) {
         $file = locate_template( $file );
    }
    return sage('blade')->render($file, $data);
}

EDIT: my original temporary fix caused \App\template($template) to break. I added an extra condition strpos($file, 'views/blocks/') !== false for this. My pull request to fix this problem doesn't need modification.

joshuafredrickson commented 3 years ago

This is fixed in 0.7.