Create a new custom activity

@param array $fields
@throws MarketoApiException

@see http://developers.marketo.com/rest-api/endpoint-reference/lead-database-endpoint-reference/#!/Activities/addCustomActivityUsingPOST
774626
public function create(array $fields)
    {
        $url = $this->client->url . "/rest/v1/activities/external.json";
        $response = $this->post($url, ['input' => $fields]);

        if (!$response->success) {
            throw new MarketoApiException('Error creating custom activity: ' . $response->errors[0]->message);
        }
    }
104097
public function append (Field $field)
    {
        if (in_array($field, $this->_fields, true)) {
            throw new InvalidArgumentException("{$this} already contains {$field}");
        }
        $this->_fields []= $field;
    }
894981
public function addActivity(\CampaignChain\CoreBundle\Entity\Activity $activities)
    {
        $this->activities[] = $activities;

        return $this;
    }
598476
public function addActivities($activities)
    {
        foreach ($activities as &$activity) {
            if (array_key_exists('to', $activity)) {
                $activity['to'] = $this->signToField($activity['to']);
            }
        }

        return $this->makeHttpRequest("{$this->base_feed_url}/", 'POST', compact('activities'), null, 'feed', 'write');
    }
1250170
public function setFields (array $fields)
    {
        $this->_fields = array();
        foreach ($fields as $field) {
            $this->append($field);
        }
    }
1270232
protected function fields(array $fields) {
        if (!empty($fields)) {
            if (!is_numeric(key($fields))) {
                $fields = array_keys($fields);
            }
            $this->insertFields = $fields;
        }
        return $this;
    }
529466
public function addFields($fields)
    {
        if ($fields instanceof FieldsBuilder) {
            $builder = clone $fields;
            $fields = $builder->getFields();
        }

        foreach ($fields as $field) {
            $this->getFieldManager()->pushField($field);
        }

        return $this;
    }
797374
public static function create($field, \SplPriorityQueue $namespaces = null)
    {
        if ($field instanceof \SimpleXMLElement) {
            $field = static::createByXml($field, $namespaces);
        } elseif (is_string($field) && class_exists($field)) {
            $field = new $field();
        } elseif (is_string($field)) {
            $xml = new \SimpleXMLElement($field);

            $field = static::createByXml($xml, $namespaces);
        } elseif (!($field instanceof AbstractField)) {
            throw new \InvalidArgumentException(
                'Windwalker\\Form\\Form::addField() need AbstractField or SimpleXMLElement.'
            );
        }

        return $field;
    }
1332270
public function update(array $fields = []) {
        $query = new UpdateQuery($this->getTable());
        $query->fields(!empty($fields)? $fields : $this->getFields());
        $query->whereConditionGroup($this->getWhereConditionGroup());
        return $this->connection->exec($query);
    }
56567
public function fillKeyField(array &$fields)
    {
        $model   = $this->config->getDataModel();
        $keyName = $model->getKeyName();

        //add the primary key field, which will be uneditable, but part of the data model
        if ($this->config->getType() === 'model' && !isset($fields[$keyName])) {
            $keyField         = $this->make($keyName, array('visible' => false));
            $fields[$keyName] = $keyField->getOptions();
        }
    }
1306277
protected function createFieldInstances($message_type, array $fields) {
    foreach ($fields as $field) {
      $id = 'message.' . $message_type . '.' . $field['name'];
      $config_storage = \Drupal::entityTypeManager()
        ->getStorage('field_config');
      // Create field instances if they do not exists.
      if ($config_storage->load($id) === NULL) {
        $field_instance = [
          'langcode' => 'en',
          'status' => TRUE,
          'config' => [
            'field.storage.message.' . $field['name'],
            'message.template.' . $message_type,
          ],
          'module' => ['options'],
          'id' => $id,
          'field_name' => $field['name'],
          'entity_type' => 'message',
          'bundle' => $message_type,
          'label' => '',
          'description' => '',
          'required' => FALSE,
          'translatable' => FALSE,
          'default_value' => [],
          'default_value_callback' => '',
          'field_type' => $field['type'],
        ];

        if ($field['type'] === 'list_string') {
          $field_instance['module'] = ['options'];
          $field_instance['settings'] = [];
        }
        elseif ($field['type'] === 'dynamic_entity_reference') {
          $field_instance['module'] = ['dynamic_entity_reference'];
          $field_instance['settings'] = [];
        }
        $config_storage->create($field_instance)->save();
      }
    }
  }
1358694
public function setMapping(array $fields = [])
    {
        $allowedFields = ['backend', 'page', 'navigation', 'date', 'forward', 'custom1', 'custom2', 'custom3', 'custom4', 'custom5'];
        foreach ($fields as $field => $value) {
            if (!$value || !in_array($field, $allowedFields)) {
                continue;
            }
            if ($field === 'date' && is_string($value)) {
                $value = new \DateTime($value);
            }
            $this->$field = $value;
        }

        return $this;
    }
487625
public function updateField($field)
    {
        if (!$field instanceof ObjectField)
        {
            throw new FieldEditorException(print_r($field, true) . " is not of type ObjectField");
        }
        foreach ($this->_fields as $column => $fields)
        {
            foreach ($fields as $index => $f)
            {
                $existing_field = $f->getField();
                if ($existing_field !== null && $field->getField() === $existing_field)
                {
                    // If the field name (f1234) exists merge replace on that.
                    $this->_fields[$column][$index] = $field;
                    return;
                }
            }
        }
        throw new FieldEditorException("Could not find an existing field: {$field->getField()} in this Section");
    }
862577
private function build_fields( $fields, $columns ) {
		if ( ! isset( $fields ) ) {
			$fields = [ '*' ];
		}
		if ( is_string( $fields ) ) {
			$fields = [ $fields ];
		}
		if ( ! empty( $fields ) ) {
			foreach ( $fields as $k => $option ) {
				$key = $k;
				if ( is_int( $key ) ) {
					$key    = $option;
					$option = null;
				}
				if ( $key === '*' ) {
					if ( ! is_array( $option ) ) {
						unset ( $fields[ $k ] );
						$is_admin = is_admin() && ! $this->app->utility->doing_ajax();
						foreach ( $columns as $key => $column ) {
							if ( ! $is_admin && ! empty( $column['only_admin'] ) ) {
								continue;
							}
							$name     = $this->app->utility->array_get( $column, 'name' );
							$fields[] = $name === $key ? $name : $name . ' AS ' . $key;
						}
						continue;
					}
					$name = $key;
				} elseif ( isset( $columns[ $key ] ) ) {
					$name = $columns[ $key ]['name'];
				} else {
					$name = $key;
				}
				if ( is_array( $option ) ) {
					$group_func = $option[0];
					if ( strtoupper( $group_func ) == 'AS' ) {
						$fields[ $k ] = $name;
						if ( count( $option ) >= 2 ) {
							$fields[ $k ] .= ' AS ' . $option[1];
						}
					} else {
						$fields[ $k ] = "$group_func( $name )";
						if ( count( $option ) >= 2 ) {
							$fields[ $k ] .= ' AS ' . $option[1];
						}
					}
				} elseif ( ! isset( $option ) ) {
					$fields[ $k ] = $name === $key ? $name : $name . ' AS ' . $key;
				} else {
					$fields[ $k ] = $name . ' AS ' . $option;
				}
			}
		}
		if ( empty( $fields ) || ! is_array( $fields ) ) {
			$fields   = [];
			$is_admin = is_admin() && ! $this->app->utility->doing_ajax();
			foreach ( $columns as $key => $column ) {
				if ( ! $is_admin && ! empty( $column['only_admin'] ) ) {
					continue;
				}
				$name     = $this->app->utility->array_get( $column, 'name' );
				$fields[] = $name === $key ? $name : $name . ' AS ' . $key;
			}
		}
		empty( $fields ) and $fields = [ '*' ];
		$fields = implode( ', ', $fields );

		return $fields;
	}
426738
public static function factory (array $field) 
    {
        foreach (array('tag', 'occurrence', 'subfields') as $index) {
            if (!array_key_exists($index, $field)) {
                throw new InvalidArgumentException("Missing '{$index}' index in field array");
            }
        }
        return new Field($field['tag'],
                         $field['occurrence'],
                         array_map(array('HAB\Pica\Record\Subfield', 'factory'), $field['subfields']));
    }
666251
function create_field( $field )
	{
		// global
		global $post;
		
		
		// vars
		$args = array(
			'numberposts' => -1,
			'post_type' => null,
			'orderby' => 'title',
			'order' => 'ASC',
			'post_status' => array('publish', 'private', 'draft', 'inherit', 'future'),
			'suppress_filters' => false,
		);
		
		
		// load all post types by default
		if( in_array('all', $field['post_type']) )
		{
			$field['post_type'] = apply_filters('acf/get_post_types', array());
		}
		
		
		// create tax queries
		if( ! in_array('all', $field['taxonomy']) )
		{
			// vars
			$taxonomies = array();
			$args['tax_query'] = array();
			
			foreach( $field['taxonomy'] as $v )
			{
				
				// find term (find taxonomy!)
				// $term = array( 0 => $taxonomy, 1 => $term_id )
				$term = explode(':', $v); 
				
				
				// validate
				if( !is_array($term) || !isset($term[1]) )
				{
					continue;
				}
				
				
				// add to tax array
				$taxonomies[ $term[0] ][] = $term[1];
				
			}
			
			
			// now create the tax queries
			foreach( $taxonomies as $k => $v )
			{
				$args['tax_query'][] = array(
					'taxonomy' => $k,
					'field' => 'id',
					'terms' => $v,
				);
			}
		}
		
		
		// Change Field into a select
		$field['type'] = 'select';
		$field['choices'] = array();
		
		
		foreach( $field['post_type'] as $post_type )
		{
			// set post_type
			$args['post_type'] = $post_type;
			
			
			// set order
			$get_pages = false;
			if( is_post_type_hierarchical($post_type) && !isset($args['tax_query']) )
			{
				$args['sort_column'] = 'menu_order, post_title';
				$args['sort_order'] = 'ASC';
				
				$get_pages = true;
			}
			
			
			// filters
			$args = apply_filters('acf/fields/post_object/query', $args, $field, $post);
			$args = apply_filters('acf/fields/post_object/query/name=' . $field['_name'], $args, $field, $post );
			$args = apply_filters('acf/fields/post_object/query/key=' . $field['key'], $args, $field, $post );
			
			
			if( $get_pages )
			{
				$posts = get_pages( $args );
			}
			else
			{
				$posts = get_posts( $args );
			}
			
			
			if($posts) {
				
				foreach( $posts as $p ) {
					
					// title
					$title = get_the_title( $p->ID );
					
					
					// empty
					if( $title === '' ) {
						
						$title = __('(no title)', 'acf');
						
					}
					
					
					// ancestors
					if( $p->post_type != 'attachment' ) {
						
						$ancestors = get_ancestors( $p->ID, $p->post_type );
						
						$title = str_repeat('- ', count($ancestors)) . $title;
						
					}
					
					
					// status
					if( get_post_status( $p->ID ) != "publish" ) {
						
						$title .= ' (' . get_post_status( $p->ID ) . ')';
						
					}
					
					
					// WPML
					if( defined('ICL_LANGUAGE_CODE') ) {
						
						$title .= ' (' . ICL_LANGUAGE_CODE . ')';
						
					}
					
					
					// filters
					$title = apply_filters('acf/fields/post_object/result', $title, $p, $field, $post);
					$title = apply_filters('acf/fields/post_object/result/name=' . $field['_name'] , $title, $p, $field, $post);
					$title = apply_filters('acf/fields/post_object/result/key=' . $field['key'], $title, $p, $field, $post);
					
					
					// add to choices
					if( count($field['post_type']) == 1 )
					{
						$field['choices'][ $p->ID ] = $title;
					}
					else
					{
						// group by post type
						$post_type_object = get_post_type_object( $p->post_type );
						$post_type_name = $post_type_object->labels->name;
					
						$field['choices'][ $post_type_name ][ $p->ID ] = $title;
					}
					
					
				}
				// foreach( $posts as $post )
			}
			// if($posts)
		}
		// foreach( $field['post_type'] as $post_type )
		
		
		// create field
		do_action('acf/create_field', $field );
	}
1002272
public function setFields(array $fields)
    {
        $this->clearFields();

        foreach ($fields as $field) {
            $this->addField($field);
        }

        return $this;
    }