Error in twig ("View [text] not found.") on using form builder
Created 6 years ago by emergingdzns

I've got a new module. It's very basic. When going to the admin panel and clicking the New button on the first section in the admin panel, I am getting these two crazy errors:

[2017-11-12 15:48:54] local.ERROR: An exception has been thrown during the rendering of a template ("An exception
has been thrown during the rendering of a template ("View [text] not found.")."). 
{"userId":1,"email":"awc@emergingdesigns.com","exception":"[object] (ErrorException(code: 0): An exception has been
thrown during the rendering of a template (\"An exception has been thrown during the rendering of a template (\"View
[text] not found.\").\"). at vendor/anomaly/streams-platform/src/View/Command/../../../resources/views/form/partials
/fields.twig:4, Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"An 
exception has been thrown during the rendering of a template (\"View [text] not found.\").\"). at 
vendor/anomaly/streams-platform/src/View/Command/../../../resources/views/form/partials/fields.twig:4, 
ErrorException(code: 0): An exception has been thrown during the rendering of a template (\"View [text] not
found.\"). at vendor/anomaly/streams-platform/src/View/Command/../../../resources/views/form/partials/wrapper.twig:39,
Twig_Error_Runtime(code: 0): An exception has been thrown during the rendering of a template (\"View [text] not 
found.\"). at vendor/anomaly/streams-platform/src/View/Command/../../../resources/views/form/partials/wrapper.twig:39,
InvalidArgumentException(code: 0): View [text] not found. at 
vendor/laravel/framework/src/Illuminate/View/FileViewFinder.php:137)

[2017-11-12 15:48:57] local.ERROR: Call to a member function parameters() on null {"userId":1,"email":"awc@emergingdesigns.com","exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalThrowableError(code: 0): Call to a member function parameters() on null at vendor/laravel/framework/src/Illuminate/Http/Request.php:557)

This view is created by Pyro using the form builder in the admin panel. The controller was created by creating the stream. I haven't modified ANYTHING in the controller. I haven't touched any form builder stuff. Twig errors are a PITA to figure out because there's zero indication of what broke it. Here's the initial module migration:

<?php

use Anomaly\Streams\Platform\Database\Migration\Migration;
use Evet\HorsesModule\Horse\HorseModel;
use Evet\HorsesModule\Payment\PaymentModel;

class EvetModuleHorsesCreateHorsesFields extends Migration
{
    /**
     * The addon fields.
     *
     * @var array
     */
    protected $fields = [
        'name' => [
            'type' => 'anomaly.field_type.text'
        ],
        'gender' => [
            "type"   => "anomaly.field_type.select",
            "config" => [
                "options"       => ['Mare', 'Stallion', 'Gelding'],
                "default_value" => null,
                "mode"          => "dropdown"
            ]
        ],
        'year_born' => [
            'type' => 'anomaly.field_type.integer'
        ],
        'color' => [
            'type' => 'anomaly.field_type.text'
        ],
        'documents' => [
            "type"   => "anomaly.field_type.files",
            "config" => [
                "folders"  => ['documents'],
                "max_size" => 80,
                "min"      => 0,
                "max"      => 6,
                "mode"     => "default",
            ]
        ],
        'registration_number' => [
            'type' => 'anomaly.field_type.text'
        ],
        'microchip' => [
            'type' => 'anomaly.field_type.text'
        ],
        'breed' => [
            'type' => 'anomaly.field_type.text'
        ],
        'breed_registry' => [
            'type' => 'anomaly.field_type.text'
        ],
        'sire' => [
            'type' => 'anomaly.field_type.text'
        ],
        'dam' => [
            'type' => 'anomaly.field_type.text'
        ],
        'breeder' => [
            'type' => 'anomaly.field_type.text'
        ],
        'breeder_usef' => [
            'type' => 'anomaly.field_type.text'
        ],
        'country_foaled' => [
            "type"   => "anomaly.field_type.country",
            "config" => [
                "default_value" => "US",
                "top_options"   => ["US", "CA", "MX"],
                "mode"          => "text",
                "handler"       => "Anomaly\CountryFieldType\Handler\DefaultHandler@handle"
            ]
        ],
        'trainer_name' => [
            'type' => 'anomaly.field_type.text'
        ],
        'trainer_phone' => [
            'type' => 'anomaly.field_type.text'
        ],

        'usef' => [
            'type' => 'anomaly.field_type.text'
        ],
        'member' => [
            'type'   => 'anomaly.field_type.relationship',
            'config' => [
                'mode'    => 'lookup',
                'related' => 'Anomaly\UsersModule\User\UserModel',
            ],
        ],
    ];
}

Here's the assignment of the fields to the stream:

<?php

use Anomaly\Streams\Platform\Database\Migration\Migration;

class EvetModuleHorsesCreateHorsesStream extends Migration
{
    /**
     * The stream definition.
     *
     * @var array
     */
    protected $stream = [
        'slug' => 'horses',
         'title_column' => 'name',
         'translatable' => true,
         'trashable' => false,
         'searchable' => false,
         'sortable' => false,
    ];

    /**
     * The stream assignments.
     *
     * @var array
     */
    protected $assignments = [
        'name' => [
            'required' => true
        ],
        'gender' => [
            'required' => true
        ],
        'year_born' => [
            'required' => true
        ],
        'color' => [
            'required' => true
        ],
        'documents',
        'registration_number',
        'microchip',
        'breed' => [
            'required' => true
        ],
        'breed_registry' => [
            'required' => true
        ],
        'sire' => [
            'required' => true
        ],
        'dam' => [
            'required' => true
        ],
        'breeder',
        'breeder_usef',
        'country_foaled' => [
            'required' => true
        ],
        'trainer_name',
        'trainer_phone',
        'usef' => [
            'required' => true
        ],
        'member' => [
            'required' => true
        ],
    ];
}

I can't figure out where to go from here. I've tried following the stack trace but I am just not finding anything helpful. I don't understand where the error is coming from if it's using the default form builder functionality.

piterden  —  6 years ago Best Answer

There is no text mode for the country FT!

emergingdzns  —  6 years ago

Oh good grief. I guess that's what I get for copy/paste from the documentation (https://pyrocms.com/documentation/country-field-type/latest) Thank @piterden !

piterden  —  6 years ago

NP)

PS Remove your log towel, please.

william  —  6 years ago

File an issue @emergingdzns if the doc is wrong.

emergingdzns  —  6 years ago

@william interestingly the documentation does say that there is a text mode for country. But apparently it's wrong. I'll file an issue. Changing it to drop down did fix the issue.

ryanthompson  —  6 years ago

I think text should actually exist on state and country both - but looks like docs are inconsistent so I will correct those. Making sure not to bump anything that works now. Thanks for the heads up!

ryanthompson  —  6 years ago

Ok so the docs were just inconsistent - they both have input, dropdown, and search modes. I'll double check docs but looks like they have already been corrected. I'll also correct the github docs so they are the same when we switch over (@piterden heads up)

piterden  —  6 years ago

Because they shouldn't be separated, IMHO. Only one select field can support state, country and others. Also, support single and multiple modes.

piterden  —  6 years ago

@ryanthompson, why the exception doesn't tell us, about we define wrong mode?