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

GridInput in EE4

Development and Programming

borareed's avatar
borareed
17 posts
about 7 years ago
borareed's avatar borareed

I’m working on updating a custom addon from EE3 to EE4. This addon is built on top of lamplighter (https://devot-ee.com/add-ons/lamplighter which is an addon that helps track updates for other addons) and enables site admins to make notes about particular addons that might be custom developed or be sourced from other sites besides devotee.

One of the parts of this custom addon on is a simple view that utilizes the CP/Table service, specifically GridInput, to list all the addons that are custom developed. In EE3, when we wanted to add a row, the plus button would create a new blank row at the bottom of the grid. However, trying this out in EE4, the add button seems broken. The page reloads, but no row is added.

public function custom_addons()
 {
  ee()->view->cp_page_title = lang('custom_addons');

  $form_url = ee('CP/URL', 'addons/settings/lampligher_custom/update_custom_addons/');

  $query = ee()->db->select()
   ->from('lampligher_custom_addons')
   ->order_by('package', 'asc')
   ->get();

  $customized = array();
  foreach ($query->result() as $row) {
   $customized[] = $row->package;
  }

  $grid = ee('CP/GridInput', array(
   'field_name' => 'custom_addons',
   'reorder'    => FALSE, // Order doesn't matter here
  ));

  $grid->loadAssets();
  $grid->setColumns(
   array(
    'addon_name' => array(
     'desc'  => 'addon_name_desc'
    )
   )
  );

  $grid->setNoResultsText('no_custom_addons', 'add_custom_addon');

  $data = array();
  $i = 0;
  foreach ($customized as $custom_addon) {
   $data[] = array(
    'attrs' => array('row_id' => $i),
    'columns' => array(
     form_input('addon_name', $custom_addon)
    )
   );

   $i++;
  }

  $grid->setData($data);
  $grid->setBlankRow(array(
   form_input('addon_name', '')
  ));

  $vars['grid'] = $grid->viewData();
  $vars['form_url'] = $form_url->compile();

  return ee('View')->make('lampligher_custom:mcp_custom_addons')->render($vars);
 }

And then the view template is:

<h2>Custom Addons</h2>



<?php 
echo ee('CP/Alert')->get('update_success');
?>
<?php echo form_open($form_url);?>

<div class="grid-publish">
 <?php $this->embed('ee:_shared/table', $grid); ?>
</div>
<input class="btn" type="submit" value="Save" data-submit-text="Save" data-work-text="Saving...">
<?php echo form_close();?>

Any idea why this would not be working in EE4?

       

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.