newbie LAC Posted April 12, 2016 Posted April 12, 2016 Hello, Please refactor AdvertisementLocations extension. Allow set position for settings. /** * Get the locations and the additional settings * * @param array $settings Current setting values * @return array Array with two elements: 'locations' which should have keys as the location keys and values as the fields to toggle, and 'settings' which are additional fields to add to the form */ public function getSettings( $settings ) { I added $formFields = array( new \IPS\Helpers\Form\Text( 'ad_test_setting1', isset($settings['ad_test_setting1']) ? $settings['ad_test_setting1'] : null, false, array(), null, null, null, 'ad_test_setting1' ), new \IPS\Helpers\Form\Text( 'ad_test_setting2', isset($settings['ad_test_setting2']) ? $settings['ad_test_setting2'] : null, false, array(), null, null, null, 'ad_test_setting2' ), ); return array( 'locations' => array( 'ad_test_location' => array('ad_test_setting1', 'ad_test_setting2' ) ), 'settings' => $formFields ); When I checked ad_test_location my settings appear above Show the advertisement Currently I need to create an additional hook to solve the problem. applications/core/modules/admin/promotion/advertisements.php /* Now grab ad location extensions */ foreach ( \IPS\Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension ) { $result = $extension->getSettings( $currentValues ); $defaultLocations = array_merge( $defaultLocations, $result['locations'] ); if( isset( $result['settings'] ) ) { foreach( $result['settings'] as $setting ) { $form->add( $setting ); // I can't add position here. Param $after } } } 1. I changed to $advLocationsSettings = array(); /* Now grab ad location extensions */ foreach ( \IPS\Application::allExtensions( 'core', 'AdvertisementLocations', FALSE, 'core' ) as $key => $extension ) { $result = $extension->getSettings( $currentValues ); $defaultLocations = array_merge( $defaultLocations, $result['locations'] ); if (is_array($result['settings']) and count($result['settings'])) { foreach($result['settings'] as $setting) { if (is_array($setting) and count($setting) and isset($setting['field']) and $setting['field'] instanceof \IPS\Helpers\Form\FormAbstract) { $advLocationsSettings[] = array( 'field' => $setting['field'], 'after' => (isset($setting['after']) and $setting['after']) ? $setting['after'] : 'ad_image_medium', ); } } } } 2. Added before /* Handle submissions */ if ( $values = $form->values() ) /* Add settings from AdvertisementLocations extensions */ if (count($advLocationsSettings)) { foreach ($advLocationsSettings as $locSetting) { $form->add( $locSetting['field'], $locSetting['after'] ); } } 3. Changed extension code $formFields = array( array( 'field' => new \IPS\Helpers\Form\Text( 'ad_test_setting1', isset($settings['ad_test_setting1']) ? $settings['ad_test_setting1'] : null, false, array(), null, null, null, 'ad_test_setting1' ), 'after' => 'ad_location' ), array( 'field' => new \IPS\Helpers\Form\Text( 'ad_test_setting2', isset($settings['ad_test_setting2']) ? $settings['ad_test_setting2'] : null, false, array(), null, null, null, 'ad_test_setting2' ), 'after' => 'ad_location_custom' ), ); return array( 'locations' => array( 'ad_test_location' => array('ad_test_setting1', 'ad_test_setting2') ), 'settings' => $formFields ); Result
Recommended Posts
Archived
This topic is now archived and is closed to further replies.