We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Need help on a simple fieldframe fieldtype

Development and Programming

iain's avatar
iain
317 posts
16 years ago
iain's avatar iain

Hey,

I need some help to build a really simple fieldtype that outputs a plain text cell within a matrix.

I’m most of the way there, but I’m struggling to output the “Col Name” variable in the cell along side the row count,

In my code below, I’d like to have “image_” set/replaced by the “Col Name” in the preferences for that field..

can anybody help please?

<?php

if ( ! defined('EXT')) exit('Invalid file request');

$row_count = 0;

/**
 * Copee Pastee Helper Field Class
 */

class Iu_copee_helper extends Fieldframe_Fieldtype {
 
    var $info = array(
        'name'             => 'Copee Pastee Helper',
        'version'          => '1.0.0',
        'desc'             => 'Outputs row count after your field name for copy/paste',
        'docs_url'         => '',
        'versions_xml_url' => ''
    );
 
    function display_field($field_name, $field_data)
    {
        global $DSP, $FF;
        global $row_count;
        $helper = $DSP->div('box row-counter');
           $helper .= "{image_".$row_count++."}";
        $helper .= $DSP->div_c();
        return $helper;
    }
 
    function display_cell($cell_name, $cell_data)
    {
        return $this->display_field($cell_name, $cell_data);
        $row_count ++;
    }
 
}

?>

If you’re wondering why the heck I would build such a thing, its for assisting publishers with the LG Replace plugin by Leevi Graham.

       
Max Lazar's avatar
Max Lazar
337 posts
16 years ago
Max Lazar's avatar Max Lazar

If I right, there is no variables with coll_name.

2 solutions from me side: 1. Add field setting like “prefix_for_cell” example:

<?php

if ( ! defined('EXT')) exit('Invalid file request');




/**
* Copee Pastee Helper Field Class
*/

class Iu_copee_helper extends Fieldframe_Fieldtype {
    
    var $info = array(
    'name'             => 'Copee Pastee Helper',
    'version'          => '1.0.0',
    'desc'             => 'Outputs row count after your field name for copy/paste',
    'docs_url'         => '',
    'no_lang'  => TRUE,
    'versions_xml_url' => ''
    );
    var $row_count = 0;
    
    var $default_field_settings_settings = array(
    'label' => 'images'
    );
    
    var $default_cell_settings = array(
    'label' => 'images'
    );
    
    function display_field_settings($field_settings)
    {
        global $DSP;
        
        $cell2  = '<label class="itemWrapper">'
        . $DSP->qdiv('defaultBold', 'Label:')
        . $DSP->input_text('label',(isset($field_settings['label'])) ? $field_settings['label'] : 'image', '2', '2','input', '60px')
        . '</label>';
        
        return array('cell2' => $cell2);
    }
    
    function display_cell_settings($cell_settings)
    {
        global $DSP, $LANG;
        $r  = '<label class="itemWrapper">'
        . $DSP->qdiv('defaultBold', 'Label:')
        . $DSP->input_text('label',(isset($cell_settings['label'])) ? $cell_settings['label'] : 'image', '2', '2','input', '80px')
        . '</label>';
        return $r;
    }
    
    function display_field($field_name, $field_data, $field_settings)
    {
        global $DSP, $FF;
        $helper = $DSP->div('box row-counter');
        $helper .= '{'.$field_settings['label']."_".$this->row_count++."}";
        $helper .= $DSP->div_c();
        return $helper;
    }
    
    function display_cell($cell_name, $cell_data, $cell_settings)
    {
        return $this->display_field($cell_name, $cell_data, $cell_settings);
        $this->row_count++;
    }
    
}
?>
  1. Create label with jQuery power. It’s more powerful, because 1 variant will formed the label in page load process. With js you can create dynamic field text for new row..
       
Brandon Kelly's avatar
Brandon Kelly
257 posts
16 years ago
Brandon Kelly's avatar Brandon Kelly

First, if you’re only interested in creating a FF Matrix celltype, you should move all your display_field code into display_cell, and remove display_field entirely.

There was in fact no easy way to get the current column name, but I think there should be. So I just made it accessible. Download the latest on GitHub, and this should work:

global $FFM;

$col_name = $FFM->col['name'];
       
iain's avatar
iain
317 posts
16 years ago
iain's avatar iain

Thanks for the help guys,

Brandon, I’ve updated to the latest Fieldframe, and modified my code as per your recommendation but its now outputting an error notice:

my code:

<?php

if ( ! defined('EXT')) exit('Invalid file request');

$row_count = 0;

/**
 * Copee Pastee Helper Field Class
 */

class Iu_copee_helper extends Fieldframe_Fieldtype {
 
    var $info = array(
        'name'             => 'Copee Pastee',
        'version'          => '1.0.0',
        'desc'             => 'Outputs row count after your field name for copy/paste',
        'docs_url'         => '',
        'versions_xml_url' => ''
    );
 
    function display_cell($cell_name, $cell_data)
    {
        global $DSP, $FF, $FFM;
    $col_name = $FFM->col['name'];
        global $row_count;
        $this->include_js('scripts/jquery.iu_copee_helper.php');
        $helper = $DSP->div('box row-counter');
           $helper .= "".$col_name.$row_count++."";
        $helper .= $DSP->div_c();
        return $helper;
    }
 
}

?>

Error notice: Notice: Undefined property: Ff_matrix::$col in /home/…/extensions/fieldtypes/iu_copee_helper/ft.iu_copee_helper.php on line 27

Sorry, I’m a noob… Have I done something wrong in the code?

       
Brandon Kelly's avatar
Brandon Kelly
257 posts
16 years ago
Brandon Kelly's avatar Brandon Kelly

are you sure you updated ft.ff_matrix.php?

       
iain's avatar
iain
317 posts
16 years ago
iain's avatar iain

Quite, I just uploaded again to make sure…

       
Brandon Kelly's avatar
Brandon Kelly
257 posts
16 years ago
Brandon Kelly's avatar Brandon Kelly

and when you said “the latest FieldFrame” you do mean from GitHub.com, right? Not brandon-kelly.com?

       
iain's avatar
iain
317 posts
16 years ago
iain's avatar iain

yes 😊

Download brandonkelly/bk.fieldframe.ee_addon at master -> I selected the Zip version…

was there somewhere else on that page I should get it from?…

       
iain's avatar
iain
317 posts
16 years ago
iain's avatar iain

Fyi, the error is only displaying when editing the matrix field,

attached is a screenshot of the settings, the fieldtype is doing what I wanted it to do, except for the notice…

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.