Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » ComplexTableField Popup problem

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 2877 Views
  • fordy
    Avatar
    Community Member
    46 Posts

    ComplexTableField Popup problem Link to this post

    I have finally got my head around creating new sections in the cms using complextablefield's but i am running into a few probs. I am getting the following error when opening the popup field on some instances.

    FATAL ERROR: Form::callfieldmethod() Field 'MembersList' not found
    At line 590 in /Applications/MAMP/htdocs/career/sapphire/forms/Form.php

    I cant find why it is happening. Here is my code...

    $section = $this->Section();
          
          if($section == 'employers') {
             $title = "<h2>Employers</h2>";
             $filter = "Group_Members.GroupID = 2";
             $sort = "Member.ID Desc";
          
          }else if ($section == 'candidates'){
             
             $title = "<h2>Candidates</h2>";
             $filter = "Group_Members.GroupID = 3";
             $sort = "Member.ID Desc";
          }
          
          $fieldList = array(
             'ID'=> 'ID',
             'FirstName' => 'First name',
             'Surname' => 'Surname',
             'Email' => 'Email',
             'Company' => 'Company',
             'City' => 'City',
             'Country' => 'Country',
             
          );
          
          $detailFields = new FieldSet();
        $detailFields->push( new TextField( 'FirstName', 'Firstname' ) );
        $detailFields->push( new TextField( 'Surname', 'Surname' ) );
        $detailFields->push( new TextField( 'Email', 'Position' ) );
          $detailFields->push( new TextField( 'Company', 'Company' ) );
          $detailFields->push( new TextField( 'Address', 'Address Line 1' ) );
          $detailFields->push( new TextField( 'Address2', 'Address Line 2' ) );
          $detailFields->push( new TextField( 'City', 'City' ) );
          $detailFields->push( new TextField( 'ZipCode', 'Zip / Postal Code' ) );
          $detailFields->push( new TextField( 'Country', 'Country' ) );
          $detailFields->push( new TextField( 'HomePhone', 'Telephone' ) );
          $detailFields->push( new TextField( 'MobilePhone', 'Mobile Phone' ) );
          $detailFields->push( new TextField( 'NumVisit', 'Number of Visits' ) );
          $detailFields->push( new TextField( 'LastVisited', 'Last Visits' ) );

          //$controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = ""
          
          $sourceJoin = "LEFT JOIN Group_Members ON Member.ID = Group_Members.MemberID";
          
          $tableList = new ComplexTableField($this,'MembersList', 'Member', $fieldList, $detailFields, $filter,$sort, $sourceJoin );
          
          $fields = new FieldSet(
             new HiddenField( 'ID' ),
             $tableList
          );
          
          //$actions = new FormAction( 'doForm', 'Save Me');
          
          return new Form($this, 'EditForm', $fields);

    Can anyone help??

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: ComplexTableField Popup problem Link to this post

    hm i don't see anything wrong with this code - are you doing some conditional switching for the fields you add to the form? a CTF popup needs the full context of the form its embedded into, so you have to make sure this context is available when being triggered through a URL (as opposed to opening the form directly). can you provide a Debug::backtrace() and the URL where this error occurs?

  • fordy
    Avatar
    Community Member
    46 Posts

    Re: ComplexTableField Popup problem Link to this post

    Cheers Ingo,

    The above code is in the EditForm() function.

    $section = $this->Section(); executes:

    public function Section() {
          $url = rtrim($_SERVER['REQUEST_URI'], '/');
          if(strrpos($url, '&')) {
             $url = substr($url, 0, strrpos($url, '&'));
          }
          $section = substr($url, strrpos($url, '/') + 1);
          
          if($section != 'employers' && $section != 'candidates' ) {
             $section = 'employers';
          }
          
          return $section;
       }

    The backtrace is:

    EmployerAdmin->EditForm()

    call_user_func_array(Array,Array)
    line 524 of ViewableData.php

    ViewableData->cachedCall(EditForm,,)
    line 565 of ViewableData.php

    ViewableData->hasValue(EditForm)
    line 7 of .cache.Applications.MAMP.htdocs.career.cms.templates.Includes.EmployerAdmin_right.ss

    include(/Applications/MAMP/htdocs/career/silverstripe-cache/.cache.Applications.MAMP.htdocs.career.cms.templates.Includes.EmployerAdmin_right.ss)
    line 190 of SSViewer.php

    SSViewer->process(EmployerAdmin)
    line 729 of ViewableData.php

    ViewableData->renderWith(Array)
    line 345 of LeftAndMain.php

    LeftAndMain->Right()

    call_user_func_array(Array,Array)
    line 376 of ViewableData.php

    ViewableData->XML_val(Right,,1)
    line 96 of .cache.Applications.MAMP.htdocs.career.cms.templates.LeftAndMain.ss

    include(/Applications/MAMP/htdocs/career/silverstripe-cache/.cache.Applications.MAMP.htdocs.career.cms.templates.LeftAndMain.ss)
    line 190 of SSViewer.php

    SSViewer->process(EmployerAdmin)
    line 245 of Controller.php

    Controller->defaultAction(index,Array)
    line 216 of Controller.php

    Controller->run(Array)
    line 76 of Director.php

    Director::direct(admin/careermembers/)
    line 110 of main.php

  • fordy
    Avatar
    Community Member
    46 Posts

    Re: ComplexTableField Popup problem Link to this post

    Still stumped on this one

    Anyone have any ideas?

  • fordy
    Avatar
    Community Member
    46 Posts

    Re: ComplexTableField Popup problem Link to this post

    Got this one fixed. Not sure how but it's working.

    I have run into a new problem though.

    I am trying to show related data via a left join on the CTF. It is filtering with the join table but not showing. How can I do this?

    Also, is there any way I can show related field data on the popup from a CTF?

    Here is my latest code...

       public function EditForm() {
          
          $section = $this->Section();
          
          //$section = 'employers';
          
          if($section == 'employers') {
             $title = "<h2>Employers</h2>";
             $filter = "Group_Members.GroupID = 2";
             $sort = "Member.ID Desc";
          
          }else if ($section == 'candidates'){
             
             $title = "<h2>Candidates</h2>";
             $filter = "Group_Members.GroupID = 3";
             $sort = "Member.ID Desc";
          }
          
          $fieldList = array(
             
             'FirstName' => 'First name',
             'Surname' => 'Surname',
             'Email' => 'Email',
             'Company' => 'Company',
             'City' => 'City',
             'Country' => 'Country',
             'GroupID' => "Group"
             
          );
          
          $detailFields = new FieldSet();
          $detailFields->push( new TextField( 'ID', 'ID'));
        $detailFields->push( new TextField( 'FirstName', 'Firstname' ) );
        $detailFields->push( new TextField( 'Surname', 'Surname' ) );
        $detailFields->push( new TextField( 'Email', 'Position' ) );
        if($section == 'employers') {
           $detailFields->push( new TextField( 'Company', 'Company' ) );
        }
          $detailFields->push( new TextField( 'Address', 'Address Line 1' ) );
          $detailFields->push( new TextField( 'Address2', 'Address Line 2' ) );
          $detailFields->push( new TextField( 'City', 'City' ) );
          $detailFields->push( new TextField( 'ZipCode', 'Zip / Postal Code' ) );
          $detailFields->push( new TextField( 'Country', 'Country' ) );
          $detailFields->push( new TextField( 'HomePhone', 'Telephone' ) );
          $detailFields->push( new TextField( 'MobilePhone', 'Mobile Phone' ) );
          $detailFields->push( new TextField( 'NumVisit', 'Number of Visits' ) );
          $detailFields->push( new TextField( 'LastVisited', 'Last Visits' ) );
          $detailFields->push( new TextField( 'GroupID', 'Group ID' ) );
          
          //$detailFields->push( new ComplexTableField($this, 'MembersVacancies', 'Vacancy', array('ID', 'vTitle'),array('ID', 'vTitle') ));

          //$controller, $name, $sourceClass, $fieldList, $detailFormFields = null, $sourceFilter = "", $sourceSort = "", $sourceJoin = ""
          
          $sourceJoin = "LEFT JOIN Group_Members ON Member.ID = Group_Members.MemberID";
          //$tableList = new ComplexTableField($this, 'VacancyList', 'Vacancy', $fieldList, $detailFields, $filter, $sort);
          $tableList = new ComplexTableField($this, 'Member', 'Member', $fieldList, $detailFields, $filter,$sort, $sourceJoin );
          
          $tableList->setPopupCaption("Add / Edit Member");
          $fields = new FieldSet(
             new HiddenField( 'ID' ),
             $tableList
          );
          
          //$actions = new FormAction( 'doForm', 'Save Me');

          return new Form($this, 'EditForm', $fields);
          
       }

  • iadawn
    Avatar
    Community Member
    13 Posts

    Re: ComplexTableField Popup problem Link to this post

    I am having a similar problem to this. Actually, it is pretty identical.

    I need to extend the Newsletter functionality (don't ask!) and have included a NewsletterBlock class which Newsletters may have many of. So I have:

    <?php
    class NewsletterBlock extends DataObject {
       static $db = array(
          'Title' => 'Varchar(255)',
          'Content' => 'HTMLText',
          'ImagePosition' => "Enum( 'Left, Right', 'Left')",
       );
       
       static $has_one = array(
          'Image' => 'Image',
          'Newsletter' => 'Newsletter',
       );

       function getCMSFields() {
          $fields = new FieldSet(
             new TextField( 'Title', _t('NewsletterBlock.Title', 'Title') ),
             new HTMLEditorField( 'Content', _t('NewsletterBlock.Title', 'Content') ),
             new ImageField( 'Image', _t('NewsletterBlock.Image', 'Image') ),
             new OptionsetField('ImagePosition', _t('NewsletterBlock.Image', 'Image position'), singleton( 'NewsletterBlock' )->dbObject('Imageposition')->enumValues() )
          );

          return $fields;
       }
       
    }
    ?>

    And I made the following additions to Newsletter.php:

       static $has_many = array(
          "Recipients" => "Newsletter_Recipient",
          "SentRecipients" => "Newsletter_SentRecipient",
          "Blocks" => "NewsletterBlock",
       );

    And, added the following into the getCMSFields method:

       $contentBlocks = new Tab(_t('Newsletter.ContentBlocks', 'Content Blocks'),
          $blockTable = new ComplexTableField(
             $controller = $this,
             $name = 'NewsletterBlock',
             $sourceClass = 'NewsletterBlock',
             $fieldList = array(
                'Title' => _t('Newsletter.Title','Title'),
                'Content' => _t('Newsletter.Content','Content'),
             )
          )
       ),

    Trouble is when I put it all together and hit the nice big 'Add Newsletter Bloc' button in the Content Blocks tab I get the following error in the pop up:

    Error is: FATAL ERROR: Form::callfieldmethod() Field 'NewsletterBlock' not found At line 633 in /Users/kevin/Sites/INSP/sapphire/forms/Form.php

    I thought I would try the latest build just to see what would happen. In there I get the following error message:

    I can't handle sub-URLs of a NewsletterAdmin object.

    I am seriously stumped on this one, so any help would be appreciated!

    Thanks

    Kevin

    2877 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.