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.
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++;
}
}
?>
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'];
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?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.