Back-end widget form

@since 0.9
@param array $instance Widget instance
162536
function form( $instance ) {

		// Loop fields
		$fields = $this->ctc_prepared_fields();
		foreach ( $fields as $id => $field ) {

			/**
			 * Field Data
			 */

			// Store data in array so custom output callback can use it
			$data = array();

			// Get field config
			$data['id'] = $id;
			$data['field'] = $field;

			// Prepare strings
			$data['default'] = isset( $data['field']['default'] ) ? $data['field']['default'] : '';
			$data['value'] = isset( $instance[$id] ) ? $instance[$id] : $data['default']; // get saved value or use default if first save
			$data['esc_value'] = esc_attr( $data['value'] );
			$data['esc_element_id'] = $this->get_field_id( $data['id'] );

			// Prepare styles for elements (core WP styling)
			$default_classes = array(
				'text'			=> 'regular-text',
				'url'			=> 'regular-text',
				'textarea'		=> '',
				'checkbox'		=> '',
				'radio'			=> '',
				'radio_inline'	=> '',
				'select'		=> '',
				'number'		=> 'small-text',
				'image'			=> '',

			);
			$classes = array();
			$classes[] = 'ctc-widget-' . $data['field']['type'];
			if ( ! empty( $default_classes[$data['field']['type']] ) ) {
				$classes[] = $default_classes[$data['field']['type']];
			}
			if ( ! empty( $data['field']['class'] ) ) {
				$classes[] = $data['field']['class'];
			}
			$data['classes'] = implode( ' ', $classes );

			// Common attributes
			$data['common_atts'] = 'name="' . $this->get_field_name( $data['id'] ) . '" class="' . esc_attr( $data['classes'] ) . '"';
			if ( ! empty( $data['field']['attributes'] ) ) { // add custom attributes
				foreach ( $data['field']['attributes'] as $attr_name => $attr_value ) {
					$data['common_atts'] .= ' ' . $attr_name . '="' . esc_attr( $attr_value ) . '"';
				}
			}

			// Field container classes
			$data['field_class'] = array();
			$data['field_class'][] = 'ctc-widget-field';
			$data['field_class'][] = 'ctc-widget-field-' . $data['id'];
			if ( ! empty( $data['field']['hidden'] ) ) { // Hidden (for internal use only, via prepare() filter)
				$data['field_class'][] = 'ctc-widget-hidden';
			}
			if ( ! empty( $data['field']['field_class'] ) ) {
				$data['field_class'][] = $data['field']['field_class']; // append custom classes
			}
			$data['field_class'] = implode( ' ', $data['field_class'] );

			// Field container styles
			$data['field_attributes'] = '';
			if ( ! empty( $data['field']['field_attributes'] ) ) { // add custom attributes
				foreach ( $data['field']['field_attributes'] as $attr_name => $attr_value ) {
					$data['field_attributes'] .= ' ' . $attr_name . '="' . esc_attr( $attr_value ) . '"';
				}
			}

			/**
			 * Form Input
			 */

			// Use custom function to render custom field content
			if ( ! empty( $data['field']['custom_field'] ) ) {
				$input = call_user_func( $data['field']['custom_field'], $data );
			}

			// Standard output based on type
			else {

				// Switch thru types to render differently
				$input = '';
				switch ( $data['field']['type'] ) {

					// Text
					// URL
					case 'text':
					case 'url': // same as text

						$input = '<input type="text" ' . $data['common_atts'] . ' id="' . $data['esc_element_id'] . '" value="' . $data['esc_value'] . '" />';

						break;

					// Textarea
					case 'textarea':

						$input = '<textarea ' . $data['common_atts'] . ' id="' . $data['esc_element_id'] . '">' . esc_textarea( $data['value'] ) . '</textarea>';

						// special esc func for textarea

						break;

					// Checkbox
					case 'checkbox':

						$input  = '<input type="hidden" ' . $data['common_atts'] . ' value="" />'; // causes unchecked box to post empty value (helps with default handling)
						$input .= '<label for="' . $data['esc_element_id'] . '">';
						$input .= '	<input type="checkbox" ' . $data['common_atts'] . ' id="' . $data['esc_element_id'] . '" value="1"' . checked( '1', $data['value'], false ) . '/>';
						if ( ! empty( $data['field']['checkbox_label'] ) ) {
							$input .= ' ' . $data['field']['checkbox_label'];
						}
						$input .= '</label>';

						break;

					// Radio
					case 'radio':

						if ( ! empty( $data['field']['options'] ) ) {

							foreach ( $data['field']['options'] as $option_value => $option_text ) {

								$esc_radio_id = $data['esc_element_id'] . '-' . $option_value;

								$input .= '<div' . ( ! empty( $data['field']['radio_inline'] ) ? ' class="ctc-widget-radio-inline"' : '' ) . '>';
								$input .= '	<label for="' . $esc_radio_id . '">';
								$input .= '		<input type="radio" ' . $data['common_atts'] . ' id="' . $esc_radio_id . '" value="' . esc_attr( $option_value ) . '"' . checked( $option_value, $data['value'], false ) . '/> ' . esc_html( $option_text );
								$input .= '	</label>';
								$input .= '</div>';

							}

						}

						break;

					// Select
					case 'select':

						if ( ! empty( $data['field']['options'] ) ) {

							$input .= '<select ' . $data['common_atts'] . ' id="' . $data['esc_element_id'] . '">';
							foreach ( $data['field']['options'] as $option_value => $option_text ) {
								$input .= '<option value="' . esc_attr( $option_value ) . '" ' . selected( $option_value, $data['value'], false ) . '> ' . esc_html( $option_text ) . '</option>';
							}
							$input .= '</select>';

						}

						break;

					// Number
					case 'number':

						// Min and max attributes
						$min = isset( $field['number_min'] ) && '' !== $field['number_min'] ? (int) $field['number_min'] : ''; // force number if set
						$max = isset( $field['number_max'] ) && '' !== $field['number_max'] ? (int) $field['number_max'] : ''; // force number if set

						$input = '<input type="number" ' . $data['common_atts'] . ' id="' . $data['esc_element_id'] . '" value="' . $data['esc_value'] . '" min="' . esc_attr( $min ) . '" max="' . esc_attr( $max ) . '" />';

						break;

					// Image
					case 'image':

						// Is image set and still exists?
						$value_container_classes = 'ctc-widget-image-unset';
						if ( ! empty( $data['value'] ) && wp_get_attachment_image_src( $data['value'] ) ) {
							$value_container_classes = 'ctc-widget-image-set';
						}

						// Hidden input for image ID
						$input .= '<input type="hidden" ' . $data['common_atts'] . ' id="' . $data['esc_element_id'] . '" value="' . $data['esc_value'] . '" />';

						// Show image
						$input .= '<div class="ctc-widget-image-preview">' . wp_get_attachment_image( $data['value'], 'medium' ) . '</div>';

						// Button to open media library
						$input .= '<a href="#" class="button ctc-widget-image-choose" data-ctc-field-id="' . $data['esc_element_id'] . '">' . _x( 'Choose Image', 'widget image field', 'church-theme-framework' ) . '</a>';

						// Button to remove image
						$input .= '<a href="#" class="button ctc-widget-image-remove">' . _x( 'Remove Image', 'widget image field', 'church-theme-framework' ) . '</a>';

						break;

				}

			}

			/**
			 * Field Container
			 */

			// Output field
			if ( ! empty( $input ) ) { // don't render if type invalid

				?>
				<div class="<?php echo esc_attr( $data['field_class'] ); ?>"<?php echo $data['field_attributes']; ?>>

					<div class="ctc-widget-name">

						<?php if ( ! empty( $data['field']['name'] ) ) : ?>

							<?php echo esc_html( $data['field']['name'] ); ?>

							<?php if ( ! empty( $data['field']['after_name'] ) ) : ?>
								<span><?php echo esc_html( $data['field']['after_name'] ); ?></span>
							<?php endif; ?>

						<?php endif; ?>

					</div>

					<div class="ctc-widget-value<?php echo ! empty( $value_container_classes ) ? ' ' . $value_container_classes : ''; ?>">

						<?php echo $input; ?>

						<?php if ( ! empty( $data['field']['desc'] ) ) : ?>
						<p class="description">
							<?php echo $data['field']['desc']; ?>
						</p>
						<?php endif; ?>

					</div>

				</div>
				<?php

			}

		}

	}
991588
protected function invokeMethods($instance)
    {
        foreach ($this->methods as $method) {
            $args = $this->resolveArguments($method['arguments']);
            call_user_func_array([$instance, $method['method']], $args);
        }

        return $instance;
    }
1136082
public function enrol_page_hook(stdClass $instance) {
        global $CFG, $OUTPUT, $USER;

        require_once("$CFG->dirroot/enrol/self/locallib.php");

        $enrolstatus = $this->can_self_enrol($instance);

        if (true === $enrolstatus) {
            // This user can self enrol using this instance.
            $form = new enrol_self_enrol_form(null, $instance);
            $instanceid = optional_param('instance', 0, PARAM_INT);
            if ($instance->id == $instanceid) {
                if ($data = $form->get_data()) {
                    $this->enrol_self($instance, $data);
                }
            }
        } else {
            // This user can not self enrol using this instance. Using an empty form to keep
            // the UI consistent with other enrolment plugins that returns a form.
            $data = new stdClass();
            $data->header = $this->get_instance_name($instance);
            $data->info = $enrolstatus;

            // The can_self_enrol call returns a button to the login page if the user is a
            // guest, setting the login url to the form if that is the case.
            $url = isguestuser() ? get_login_url() : null;
            $form = new enrol_self_empty_form($url, $data);
        }

        ob_start();
        $form->display();
        $output = ob_get_clean();
        return $OUTPUT->box($output);
    }
712006
private static function set( $instance = false ) {
		// Make sure the plugin hasn't already been instantiated before.
		global $wp_plugins;
		if ( ! isset( $wp_plugins ) ) {
			$wp_plugins = new \stdClass();
		}
		// Get the fully qualified parent class name and instantiate an instance of it.
		$called_class = get_called_class();
		$plugin_name  = strtolower( $called_class );
		if ( empty( $instance ) || ! is_a( $instance, $called_class ) ) {
			$wp_plugins->$plugin_name = new $called_class();
		} else {
			$wp_plugins->$plugin_name = $instance;
		}
	}
223112
public static function setInstance($instance)
    {
        if ($instance === null) {
            unset(Zilf::$app->loadedModules[get_called_class()]);
        } else {
            Zilf::$app->loadedModules[get_class($instance)] = $instance;
        }
    }
544757
public function created($instance)
    {
        $after = $this->recordableAttributes(get_class($instance), $instance->getAttributes());

        $instance->recordActivity('created', null, $after);
    }
1171554
public function form( $instance ) {
		$instance = shortcode_atts( $this->_defaults, $instance );
		foreach ( $instance as $key => $value ) {
			if ( is_array( $this->_defaults[ $key ] ) && isset( $this->_defaults[ $key ][0] ) && is_array( $this->_defaults[ $key ][0] ) ) {
				foreach ( array_keys( $value ) as $repeater_key ) {
					$instance[ $key ][ $repeater_key ] = shortcode_atts( $this->_defaults[ $key ][0], $instance[ $key ][ $repeater_key ] );
				}
				array_unshift( $instance[ $key ], $this->_defaults[ $key ][0] );
			}
		}
		$this->_render_form( $instance );
	}
860847
protected function _render_widget( $args, $instance ) {
		$widget_templates = apply_filters( 'inc2734_wp_awesome_widgets_widget_templates', 'templates/widget' );
		$default_template = $this->_path . '/_widget.php';
		$custom_template  = $widget_templates . '/' . basename( $this->_path );

		ob_start();

		if ( file_exists( get_theme_file_path( $custom_template . '.php' ) ) ) {
			include( get_theme_file_path( $custom_template . '.php' ) );
		} elseif ( file_exists( $default_template ) ) {
			include( $default_template );
		}

		$widget = ob_get_clean();

		if ( empty( $widget ) ) {
			return;
		}

		// @codingStandardsIgnoreStart
		echo apply_filters( 'inc2734_wp_awesome_widgets_render_widget', $widget, $args, $instance );
		// @codingStandardsIgnoreEnd
	}
691306
public function widget($args, $instance)
    {
        
        /*
         * Put the pages to show into the instance var.
         */
        $instance['pages'] = Post::getPages();
        
        /*
         * And call the widget func from the parent class WidgetBase.
         */
        parent::widget($args, $instance);
    }
621322
public function widget_start($args, $instance, $title)
    {
        echo $args['before_widget'];

        if ($title && $this->getModel()->getDisplayTitle()) {
            echo $args['before_title'].$title.$args['after_title'];
        }
    }
1226740
function save(Model $instance, array $data)
    {
        // First transform data, passing false as a second parameter to allow partial objects.
        // This is important: this save() can be the second one called in the same request
        // for any field which formatter required a delay in his execution.
        $data = $this->applyTransformers($data, false);

        // Then handle manually ignored attributes...
        if(count($this->ignoredAttributes)) {
            $data = collect($data)->filter(function ($value, $attribute) {
                return array_search($attribute, $this->ignoredAttributes) === false;
            })->all();
        }

        // Finally call updater
        return app(EloquentModelUpdater::class)
            ->initRelationshipsConfiguration($this->getFormListFieldsConfiguration())
            ->update($instance, $data);
    }
521594
public function removeInstance(WidgetInstance $instance)
    {
        if ($this->instances->contains($instance)) {
            $this->instances->removeElement($instance);
        }
    }
378897
public function endWidget($widget = null)
    {
        if ($widget === null) {
            if (empty($this->widgets)) {
                throw new TemplateException('Unexpected end_widget() call. A matching begin_widget() is not found.');
            }
            $this->call(array_pop($this->widgets), 'end');
        } else {
            array_pop($this->widgets);
            $this->resolveAndCall($widget, 'end');
        }
    }
1133127
protected function processForm($instance)
    {
        $parameters = $this->getRequestParameters();
        $form = $this->getForm($instance)->bind($parameters);
        $report = $form->validate();
        if ($report->containsError()) {
            $this->returnValidationFailure($report);
        } else {
            $resource = $form->save();
            $this->returnSuccess(['uri' => $resource->getUri()]);
        }
    }
1005890
public function newInstance($selfedit = "false", $instanceName=null, $instanceClass=null) {
        //$componentsList = Moufspector::getComponentsList();
        $this->selfedit = $selfedit;
        $componentsList = MoufReflectionProxy::getComponentsList($selfedit=="true");
        sort($componentsList);

        $template = $this->template;
        $template->addContentFunction(array($this, "displayNewInstanceScreen"), $componentsList, $selfedit, $instanceName, $instanceClass);
        //$template->addContentFile(dirname(__FILE__)."/../views/displayNewInstance.php", $this);
        $template->toHtml();
    }
84293
public function widget($args, $instance){
        $content = $this->widget_content($instance);
        if( $content ){
            echo $args['before_widget'];
            if( isset($instance['title']) && !empty($instance['title']) ){
                echo $args['before_title'];
                echo $instance['title'];
                echo $args['after_title'];
            }
            echo $content;
            echo $args['after_widget'];
        }
    }
1364377
public function front_end( $args, $instance ) {
		if ( $instance['title'] ) {
			$title = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );

			echo $args['before_title'] . $title . $args['after_title'];
		}

		echo apply_filters( 'the_content', $instance['content'] );
	}